I am using Kyslik/column-sortable in my Laravel CRUD project for added sortable column headers.
the model:
use Sortable;
//
public $sortable = ['id', 'name', 'email', 'created_at', 'updated_at'];
the view:
<table class="table table-hover">
<thead>
<tr>
<th> @sortablelink('id','#') </th>
<th> @sortablelink('name') </th>
...
</tr>
</thead>
<tbody>
</tbody>
</table>
and the controller:
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'));
}
The view and the column header links show up and work exactly as expected, but the results aren't sorted at all... What am I missing?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mq6p7U
via IFTTT
Aucun commentaire:
Enregistrer un commentaire