File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -64,7 +64,24 @@ return [
6464
6565## Basic Usage
6666
67- You can filter Eloquent models directly using the ` filter() ` scope. You can use all laravel
67+ You can filter Eloquent models directly using the ` filter() ` scope.
68+
69+ To use the query filters in your Laravel models, you must add the Filterable trait to the model. For example:
70+
71+ ``` php
72+ use Illuminate\Database\Eloquent\Model;
73+ use Obrainwave\LaravelQueryFilters\Filterable;
74+
75+ class User extends Model
76+ {
77+ use Filterable;
78+
79+ // Optional: define allowed columns in the model
80+ // protected $allowedFilters = ['name', 'email'];
81+ }
82+ ```
83+
84+ Once the trait is added, you can call the filter() method on your model statically:
6885
6986``` php
7087use App\Models\User;
@@ -73,9 +90,12 @@ $users = User::filter([
7390 'status' => 'active',
7491 'role' => 'admin',
7592 'q' => 'john', // Global search
76- ])->paginate (); // Supports per_page from request or config
93+ ])->get (); // or ->first()
7794```
7895
96+ * Without Filterable, filter() won’t exist on your model.
97+ * You can optionally define $allowedFilters in the model or rely on the config for auto-generated filters.
98+
7999And also supports laravel paginate and simplePaginate
80100
81101``` php
You can’t perform that action at this time.
0 commit comments