我在 laravel 版本上使用Yajra 数据表8.0
包。
在此之前我使用的是旧版本,我使用->orderBy('created_at', 'desc')
基于特定列对数据进行排序。
但在较新的版本中,建议使用一种orderColumn
方法进行排序。但这对我不起作用。
假设我想将Post
我网站的所有内容都排序为 desc on field created_at
。为此我写了这个:
$posts =
Post::select(['post_id', 'post_title', 'start_date', 'end_date', 'picture', 'active', 'created_at', 'deleted_at']);
if ($request->has('showDeleted') && $request->get('showDeleted') == 1) {
$posts = $posts->withTrashed();
}
$datatable = app('datatables')->of($posts)
->orderColumn('created_at', '-created_at $1');
return $datatable->make(true);
正如你所看到的,我用过orderColumn
但酸痛不起作用。而且我不知道如何正确使用它。