我在Laravel 5.4 CRUD项目中使用Kyslik/column-sortable来添加可排序的列标题。
模特:
use Sortable;
//
public $sortable = ['id', 'name', 'email', 'created_at', 'updated_at'];
观点:
<table class="table table-hover">
<thead>
<tr>
<th> @sortablelink('id','#') </th>
<th> @sortablelink('name') </th>
...
</tr>
</thead>
<tbody>
</tbody>
</table>
和控制器:
public function index(Request $request)
{
$keyword = $request->get('search');
//dd($request);
if (!empty($keyword)) {
$customers = Customer::where('name', 'LIKE', "%$keyword%")
->orWhere('email', 'LIKE', "%$keyword%")
->sortable()
->paginate(config('settings.perPage'));
} else {
$customers = Customer::paginate(config('settings.perPage'));
}
return view('admin.customers.index', compact('customers'));
}
视图和列标题链接显示和完全按预期工作,但结果根本没有排序...我缺少什么?