0

I am currently working on a Laravel project using filamentPHP. However I cannot find a way to delete the create functionality for a specific resource. Considering there is a resource named Customer, in the view page, I would like to remove the new customer button located at the top of the list. Is there any way to do that?

Marcellin Khoury
  • 336
  • 5
  • 13

4 Answers4

5

I'm using filament v2.16.66 with Laravel 9.19.

What works for me in order to remove create button in certain lists, is adding the following function in eg: App\Filament\Resources\CustomerResource

    public static function canCreate(): bool
   {
      return false;
   }
Farid
  • 542
  • 5
  • 16
  • Another way I found recently is to comment out the Create method in your ExampleResource/Pages/CreateExample.php class – Farid Apr 08 '23 at 15:26
1

A Laravel specific solution is to create a new policy, and override the create() function to return false, like the following:

public function create()
{
   return false;
}

Note: Do not forget to assign the required model to this new policy in /Providers/AuthServiceProvider.php.

Marcellin Khoury
  • 336
  • 5
  • 13
0

You can remove it by override canCreate() and return it as false.

class Customer
{
   public static $resource = CustomerResource::class;

   protected function canCreate(): bool
   {
      return false;
   }
}
Win
  • 353
  • 1
  • 8
0

You could also just remove the CreateAction::make() from the List page's getActions(). No need to override methods.

protected function getActions(): array
{
    return [
        //  Actions\CreateAction::make(),
    ];
}

Based on: https://github.com/filamentphp/filament/discussions/3774#discussioncomment-3516256

Fsamapoor
  • 71
  • 3
  • 8