$today = Carbon::today();
$search = $today->subDay(1);
$loading =LoadingBus::where('created_at','=',$search)->get();
dd($loading);
给了我一个空集合。请问我做错了什么 收集{#279▼ #items:[] } 我的loading_buses表中的数据与此特定日期匹配 了解更多信息
dd($search)
Carbon {#278 ▼
+"date": "2016-09-03 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
loading_buses created_at value = 2016-09-03 00:01:06
我真的需要帮助
答案 0 :(得分:0)
您不应传递 Carbon 对象,而应传递代表日期的字符串。
替换
$loading = LoadingBus::where('created_at','=',$search)->get();
与
$loading = LoadingBus::where('created_at','=',$search->formatLocalized('%Y%m%d%H%M%S'))->get();
答案 1 :(得分:0)
您的Carbon
实例与小时,分钟和秒的数据库记录不相等,您应该唱whereDate
mehtod。
试试这个:
$today = Carbon::today();
$search = $today->subDay(1);
$loading =LoadingBus::whereDate('created_at','=',$search->format('Y-m-d'))->get();
dd($loading);