filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.65k stars 2.76k forks source link

Filament\Tables\Filters\Filter::apply() must be instance of Closure #757

Closed ManojKiranA closed 2 years ago

ManojKiranA commented 2 years ago

Package

filament/filament

Package Version

2.x-dev

Laravel Version

8.65

Livewire Version

Not needed

PHP Version

8.0.12

Bug description

After creating the resource when i try to Create a filter I am getting the following error

TypeError
Filament\Tables\Filters\Filter::apply(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, Closure given, called in C:\xampp\htdocs\filamenttest\app\Filament\Resources\CustomerResource.php on line 49

image

I think the problem is apply Method of InteractsWithTableQuery trait will only accept instance of Illuminate\Database\Eloquent\Builder

Steps to reproduce

public static function table(Table $table): Table
    {
        return $table
            ->columns([
            TextColumn::make('first_name'),
            ])
            ->filters([
                Tables\Filters\Filter::make('verified')
                    ->apply(fn (Builder $query): Builder => $query->whereNotNull('email_verified_at')),
            ]);
    }

Relevant log output

TypeError
Filament\Tables\Filters\Filter::apply(): Argument #1 ($query) must be of type Illuminate\Database\Eloquent\Builder, Closure given, called in C:\xampp\htdocs\filamenttest\app\Filament\Resources\CustomerResource.php
danharrin commented 2 years ago

Hey, please use query() instead of apply() to set the callback. Are the docs wrong?

ManojKiranA commented 2 years ago

I am not sure that issue is in docs or method signature 😕

ManojKiranA commented 2 years ago

Hey, please use query() instead of apply() to set the callback. Are the docs wrong?

Just now figured it out

ManojKiranA commented 2 years ago

Shall I send pr to Docs with change

danharrin commented 2 years ago

Yes please, I can't see where they're incorrect though?