How to prevent access on New Company button when some subscription planned is expired?

Required disabled button not hide it. And use view that page, too.
No description
7 Replies
Dennis Koch
Dennis Koch2y ago
You should solve this via Company Policy
Sourabh
Sourabh2y ago
@Dennis Koch Can you please share any referrece for the same, So I can understand. Thanks!
DrByte
DrByte2y ago
The Filament docs indicate that Panels use Laravel Policies: https://filamentphp.com/docs/3.x/panels/resources/viewing-records#authorization The Laravel docs explain how to make Policies: https://laravel.com/docs/10.x/authorization#creating-policies
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Sourabh
Sourabh2y ago
@Dennis Koch I have checked said reference and made a policy of company but it hide the button New Company . we want application in view mode user can able to see create form and when he will click on Create button then a pop up is open and tell that your subscription is expired you will not able to create company. Thanks ,
Dennis Koch
Dennis Koch2y ago
I didn’t understand the initial question. I thought it’s about hiding the button. You need to adjust the CreateAction then. I’d probably create 2 actions, one normal form action and one with a modal and hide the other depending on the subscription status.
Sourabh
Sourabh2y ago
@Dennis Koch yes i want to controller action . is it possible by middleware as like in normal laravel ? please see below example and guide me for the same .can I able to apply here as well .if yes then please guide me for the .If no then what should i do ?.
No description
Dennis Koch
Dennis Koch2y ago
I already told you how I would solve it in my last answer. Something like this
CreateAction::make()->hidden(fn () => /* when user has no subscription */),
Action::make('create_not_possible')
->visible(fn () => /* when user has no subscription */)
->modalContent('No subscription')
->action(fn () => null)
CreateAction::make()->hidden(fn () => /* when user has no subscription */),
Action::make('create_not_possible')
->visible(fn () => /* when user has no subscription */)
->modalContent('No subscription')
->action(fn () => null)

Did you find this page helpful?