PHP code example of oscabrera / laravel-query-filters
1. Go to this page and download the library: Download oscabrera/laravel-query-filters library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
oscabrera / laravel-query-filters example snippets
return [
/*
* The name of the macro that is added to the Eloquent query builder.
*/
'method_name' => 'applyFilters',
];
use Oscabrera\QueryFilters\Utilities\QueryFilters;
use App\Models\User;
use Illuminate\Http\Request;
public function index(Request $request)
{
$conditions = [
'name' => 'John',
'age' => ['age', '>', 25],
'status' => ['active', 'pending'],
'role' => [
'subQuery' => function($query) {
return $query->select('id') ->from('roles') ->where('name', 'admin');
},
'not' => false,
]
];
$queryFilters = new QueryFilters($conditions);
$users = User::query()->applyFilters($queryFilters)->get();
return response()->json($users);
}