Skip to content
Icon

WARNING You're browsing the documentation for an old version of LARAVEL-DATATABLES. Consider upgrading your project to laravel-datatables 11.0.

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();
});