PHP code example of brnrajoriya / laravel-queryflow
1. Go to this page and download the library: Download brnrajoriya/laravel-queryflow 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/ */
brnrajoriya / laravel-queryflow example snippets
#[Queryable(
filterable: ['id', 'status', 'author_id', 'views', 'created_at'],
sortable: ['id', 'title', 'views', 'created_at'],
searchable: ['title', 'body', 'author.name'],
includable: ['author', 'comments'],
)]
class Post extends Model
{
use HasQueryFlow;
}
public function index(QueryFlowRequest $request)
{
return Post::flow()->apply($request->queryFlow())->get();
}
use BrnRajoriya\QueryFlow\Attributes\Queryable;
use BrnRajoriya\QueryFlow\Concerns\HasQueryFlow;
#[Queryable(filterable: [...], sortable: [...], searchable: [...], includable: [...])]
class Post extends Model
{
use HasQueryFlow; // optional: adds Post::flow() and $post->loadFlow()
}
use BrnRajoriya\QueryFlow\QueryFlow;
use BrnRajoriya\QueryFlow\Params;
// From a FormRequest (validation runs before the controller, API doc tools can read the rules)
$result = Post::flow()->apply($request->queryFlow())->get();
// From any array (validates too)
$result = QueryFlow::for(Post::class)->apply($request->query())->get();
// Keep your own constraints - client filters cannot escape them
$result = QueryFlow::for(Post::query()->where('user_id', $request->user()->id))
->apply($request->queryFlow())
->get();
// Relations work too
$result = QueryFlow::for($user->posts())->apply($params)->get();
// Single record: ?with=author&with_count=comments
$post->loadFlow($request->query());
class IndexRequest extends QueryFlowRequest
{
public function rules(): array
{
return [...parent::rules(), 'status' => ['sometimes', 'string']];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.