EasyFilter helps you to filter eloquent queries
composer require michelangelomo/easyfilter
use Michelangelo\EasyFilter\EasyFilter;
$filter = new EasyFilter($query);
$filter->orderByDesc('id');
$filter->whereLike('name', 'giovanni', '%', '%');
$filter->whereHasEquals('roles', 'name', 'admin');
//and other methods...
//Get some users
$users = User::where('company', 'Antani Inc.');
//Instantiating class
$filter = new EasyFilter($users);
$filter->whereCustom('id', '>=', 6);
$filter->whereNotEquals('name', 'John');
$filter->whereHasEquals('roles', 'id', 1);
$filter->whereHasNotEquals('roles', 'id', 4);
//and so on
//....
//Finally get filtered users
$users->get();