neiderruiz / filter-eloquent-laravel
filter query eloquent laravel
dev-main
2023-02-26 11:24 UTC
README
Translate text php
composer require neiderruiz/filter-eloquent-laravel
how using translator
// import pachage
use Neiderruiz\FilterEloquentLaravel\Traits\FilterQuery;
// use trait in controller
class UserController extends Controller
{
use FilterQuery;
}
// example use filter
public function index(Request $request)
{
$this->filter = User::query();
$this->addWith();
$this->where();
$this->search();
return $this->success($this->paginate());
}
// your url request
?paginate=true&search=[articles,name,laravel]&with=[articles:id,title]
// get specific fields
&inputs=id,name,email
get specific fields
// your url request
&fields=id,name,email
with relations
&with=[posts:id,title,user_id]
with multiple relations
//example one &with=[posts:id,title,user_id] // example two &with=[posts:id,title,user_id][posts.comments] // example three &with=[posts:id,title,user_id][posts.comments][posts.comments.user] // example four &with=[posts:id,title,user_id][posts.comments][posts.comments:id,description]
Simple Search
// your url request
&search=[name,your text]
Search With Relation
// your url request
&search=[articles,name,your text]
Search With Multiple Relation
// your url request
&search=[articles,name,your text][articles,description,your text]
Where
// example one &where=[id,10] // example two &where=[id,10][name,neider ruiz] // example three &where=[name,neider ruiz,like] // example four &where=[age,20,<=]
Where With Relation
// example one &where=[articles,id,10] // example two &where=[articles,title,mi titulo,like]