Conditionally add and update relations
Currently I got this situation.
A user can have only 1 shipping address and only 1 billing address.
In Filament's admin panel's user form, admin can change user's info.
However I want to set restrictions, so that admin cant give a user >1 address of type shipping, and cant give a user >1 address of type billing.
That also implies that when the user already got 1 billing address, the admin can't change that user's shipping address to type=billing.
How can something like that be done?
A user can have only 1 shipping address and only 1 billing address.
In Filament's admin panel's user form, admin can change user's info.
However I want to set restrictions, so that admin cant give a user >1 address of type shipping, and cant give a user >1 address of type billing.
That also implies that when the user already got 1 billing address, the admin can't change that user's shipping address to type=billing.
How can something like that be done?
Solution
Create a policy according to the laravel docs then handle the conditions in each method based on your apps authorization. Filament defaults to Laravel’s policies to handle model authorization. https://laravel.com/docs/11.x/authorization#creating-policies
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.

