F
Filamentβ€’12mo ago
Thijmen

Custom Operator in Query Builder

I have this code:
Constraint::make('min_max')
->label('Min-Max')
->icon('heroicon-o-adjustments-horizontal')
->operators([
Operator::make('min_max')
->label(fn (bool $isInverse): string => $isInverse ? 'Onder minimum' : 'Tussen minimum en maximum')
->summary(fn (bool $isInverse): string => $isInverse ? 'Onder minimum' : 'Tussen minimum en maximum')
->baseQuery(fn (\Illuminate\Database\Query\Builder $query, bool $isInverse) => $query->where('stock', fn (\Illuminate\Database\Query\Builder $query) => $query->whereKey(auth()->user()),)),
])
Constraint::make('min_max')
->label('Min-Max')
->icon('heroicon-o-adjustments-horizontal')
->operators([
Operator::make('min_max')
->label(fn (bool $isInverse): string => $isInverse ? 'Onder minimum' : 'Tussen minimum en maximum')
->summary(fn (bool $isInverse): string => $isInverse ? 'Onder minimum' : 'Tussen minimum en maximum')
->baseQuery(fn (\Illuminate\Database\Query\Builder $query, bool $isInverse) => $query->where('stock', fn (\Illuminate\Database\Query\Builder $query) => $query->whereKey(auth()->user()),)),
])
And i get this error from it. Argument #1 ($query) must be of type Illuminate\Database\Query\Builder, Illuminate\Database\Eloquent\Builder given Did I do something wrong here? I followed the docs so not sure.
4 Replies
Lara Zeus
Lara Zeusβ€’12mo ago
change \Illuminate\Database\Query\Builder with Illuminate\Database\Eloquent\Builder
Thijmen
ThijmenOPβ€’12mo ago
I did that but got the same error
Lara Zeus
Lara Zeusβ€’12mo ago
changed bothe of them? I guess you have third place with the same use? πŸ™‚
Thijmen
ThijmenOPβ€’12mo ago
->baseQuery(fn (\Illuminate\Database\Eloquent\Builder $query, bool $isInverse) => $query->where('stock', fn (\Illuminate\Database\Eloquent\Builder $query) => $query->whereKey(auth()->user()),)),
->baseQuery(fn (\Illuminate\Database\Eloquent\Builder $query, bool $isInverse) => $query->where('stock', fn (\Illuminate\Database\Eloquent\Builder $query) => $query->whereKey(auth()->user()),)),
App\Livewire\Replenish::App\Livewire\{closure}(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, Illuminate\Database\Query\Builder given, called in /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php on line 1673 I dont have the Eloquent Builder or the Query Builder imported somewhere in that file Looks like the first one should be \Illuminate\Database\Eloquent\Builder and second one \Illuminate\Database\Query\Builder. But if one of the maintainers can verify this that would be great. Bump If this is the right way i can make a PR for it
Want results from more Discord servers?
Add your server