Installation & Quick Start
Installation
- Install the package via Composer:
composer require victormgomes/laravel-query-engine
- Publish the configuration file:
php artisan vendor:publish --tag="laravel-query-engine-config"
Quick Start
Step 1: Auto-generate validation rules
Annotate your FormRequest with #[MapQueryEngine(Model::class)].
// app/Http/Requests/IndexUserRequest.php
use Illuminate\Foundation\Http\FormRequest;
use Victormgomes\LaravelQueryEngine\Attributes\MapQueryEngine;
use App\Models\User;
#[MapQueryEngine(User::class)]
class IndexUserRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
}
It generates the validation rules based on the model schema.
Step 2: Build the query
The package automatically adds powerful new methods directly to all your Eloquent models. You can call these anywhere in your application (such as a Controller or a Service class) by simply passing the validated request:
// app/Http/Controllers/UserController.php
use App\Models\User;
use App\Http\Requests\IndexUserRequest;
use Illuminate\Pagination\LengthAwarePaginator;
public function index(IndexUserRequest $request): LengthAwarePaginator
{
// Pass the request to automatically apply all URL parameters
return User::paginateQuery($request);
}
This returns a LengthAwarePaginator with all valid filters, sorts, includes,
and pagination automatically applied.