[英]Retrieve data from the database using Eloquent between two dates
I'm having trouble retrieving data from the database using Eloquent. 我无法使用Eloquent从数据库检索数据。 I am trying to retrieve all data between two dates ( created_at
field). 我正在尝试检索两个日期之间的所有数据( created_at
字段)。
I've done this: 我已经做到了:
public function search(Request $request){
$start_date = $request->get('start_date');
$end_date = $request->get('end_date');
$getinfo = DB::table('media')
->join('content_forms', 'media.id', "=", 'content_forms.media_id')
->whereBetween('Date_Occured',[$start_date, $end_date])
->get();
dd($getinfo);
}
if you want to select between dates of the media table for example, then fully qualify the field eg 例如,如果要在媒体表的日期之间进行选择,则完全限定该字段,例如
$getinfo = DB::table('media')
->join('content_forms', 'media.id', "=", 'content_forms.media_id')
->whereBetween('media.created_at', [$start_date, $end_date]);
->get();
Also make sure the dates passed in the request are in a correct YYYY-mm-dd format 还要确保请求中传递的日期采用正确的YYYY-mm-dd格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.