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
15.94k stars 2.54k forks source link

Table builder not respecting default Laravel Policy #13430

Closed Jeordy closed 1 week ago

Jeordy commented 1 week ago

Package

filament/tables

Package Version

v3.2.92

Laravel Version

v11.12.0

Livewire Version

v3.5.1

PHP Version

PHP 8.3.8

Problem description

When creating a filament table on a freshly installed Laravel, and using the visibility with a Policy check, there's an error:

Too few arguments to function App\Policies\PermissionPolicy::delete(), 1 passed in /Users/jeordy/Projects/PrintDeck/dev/filament-visibility-bug/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 811 and exactly 2 expected

Table:

public function table(Table $table): Table
    {
        return $table
            ->query(Permission::query())
            ->columns([
                TextColumn::make('name')
                    ->searchable()
                    ->sortable(),
                TextColumn::make('description')
                    ->searchable()
                    ->sortable(),
            ])
            ->actions([
                Action::make('delete')
                    ->requiresConfirmation()
                    ->label('Delete Permission')
                    ->visible(function () {
                        return auth()->user()->can('delete', Permission::class);
                    }),
            ]);
    }

Policy:


/**
     * Determine whether the user can delete the model.
     */
    public function delete(User $user, Permission $permission): bool
    {
        return true;
    }

Expected behavior

It should pass the policy and go to the delete() function

Steps to reproduce

Install repo, do a php artisan migrate:fresh --seed. Then register/login and go to http://yourproject.test/permissions. Click on the delete button.

Reproduction repository (issue will be closed if this is not valid)

https://github.com/Jeordy/filament-visibility-bug

Relevant log output

No response

Donate 💰 to fund this issue

Fund with Polar

zepfietje commented 1 week ago

This is not a Filament bug. You should pass the actual permission object (table record) to the can method.