Best way to reuse Create button (with permissions)

Hello, I would like to display a resource creation button in a custom modal. I want to rewrite as little code as possible and keep the permissions system (filament-shield). I have done the following:
Action::make('create_user')
->label(__('Models/user.btn.create'))
->schema(fn () => UserForm::configure(Schema::make())->getComponents())
->action(function (array $data) {
return User::create($data);
})
Action::make('create_user')
->label(__('Models/user.btn.create'))
->schema(fn () => UserForm::configure(Schema::make())->getComponents())
->action(function (array $data) {
return User::create($data);
})
But the button is still visible and works even if I do not have the permission to create a user. Do I really have to manage permissions myself? Is there no way to reuse the same behavior as the buttons on the listing page? Thanks!
1 Reply
bouly
boulyOP4w ago
Ok I found I can use:
->authorize('create', User::class)
->authorize('create', User::class)
But I feel like it's not a proper way to do so.

Did you find this page helpful?