我的模型:
protected $dates = [
'created_at',
'updated_at',
'canceled_at',
'checked_in_at',
'planned_at' => 'desc',
];
我的视图:
@if(!isset($for_date))
<td>
{{ $reservation->planned_at->formatLocalized('%x') }}
</td>
@endif
我的控制器:
if($request->filter == 'all'){
$date = new Carbon($request->date);
$this->data['reservations'] = $this->reservation_system->reservations;
}
我在模型中添加了=>'desc',这是我能想到的唯一方法,但随后他给了我错误消息:'在字符串上调用成员函数formatLocalized()'
答案 0 :(得分:0)
如果要按“ planned_at” desc排序查询,则应使用全局范围。在https://laravel.com/docs/5.7/eloquent#global-scopes
中找到文档参考