Closed fazliddin closed 9 months ago
You defined the wrong type. Please read the error carefully:
Argument #1 ($query) must be of type
Illuminate\Database\Query\Builder
,Illuminate\Database\Eloquent\Builder
given
But yes \Illuminate\Database\Query\Builder
is given
in my code i never use Illuminate\Database\Eloquent\Builder
"Given" means "passed as an argument". Filament uses Eloquent\Builder
but you declared, that you want a Query\Builder
.
OK, I changed code as you suggest:
->fromTable()
->modifyQueryUsing(function (
\Illuminate\Database\Eloquent\Builder $query,
\App\Models\Keywords $model
)
{
return $query->where('project_id', $model->project_id);
}),
Now another problem
Too few arguments to function App\Filament\Resources\ProjectsResource\RelationManagers\KeywordsRelationManager::App\Filament\Resources\ProjectsResource\RelationManagers\{closure}(), 1 passed in /var/www/vhosts/tulpor-seo/vendor/pxlrbt/filament-excel/src/Exports/ExcelExport.php on line 264 and exactly 2 expected
Now it says 1 arg is passed, but 2 args are expected.
Yes. Because $model
is not injected when using modifyQueryUsing()
. I think there is an open PR to add $livewire
and $tableQuery
. Need to look into that PR first, though. Not really sure how to solve your problem, sorry.
I can solve this problem by extending export class. But this concrete situation is result of relying on functional programming too heavily. Anonymous function are hard to read and debug. We invented OOP to be able to extent code, but again we are going back functions.
Following code gives error:
Error massage:
App\Filament\Resources\ProjectsResource\RelationManagers\KeywordsRelationManager::App\Filament\Resources\ProjectsResource\RelationManagers\{closure}(): Argument #1 ($query) must be of type Illuminate\Database\Query\Builder, Illuminate\Database\Eloquent\Builder given, called in /var/www/vhosts/tulpor-seo/vendor/pxlrbt/filament-excel/src/Exports/ExcelExport.php on line 264