Skip to content
Icon

WARNING You're browsing the documentation for an upcoming version of Laravel DataTables. The documentation and features of this release are subject to change.

Manual Search

You can optionally write your own manual filtering functions and thus disabling global search of the package. To achieve this, you can use the filter api.

Manual Searching without Global Search

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::eloquent($model)
->filter(function ($query) {
if (request()->has('name')) {
$query->where('name', 'like', "%" . request('name') . "%");
}
 
if (request()->has('email')) {
$query->where('email', 'like', "%" . request('email') . "%");
}
})
->toJson();
});

Manual Searching with Global Search

{tip} To enable global search with filter api, just set the 2nd argument to true.

use DataTables;
 
Route::get('user-data', function() {
$model = App\User::query();
 
return DataTables::eloquent($model)
->filter(function ($query) {
if (request()->has('name')) {
$query->where('name', 'like', "%" . request('name') . "%");
}
 
if (request()->has('email')) {
$query->where('email', 'like', "%" . request('email') . "%");
}
}, true)
->toJson();
});