F
Filament4mo ago
Cushty

Create hasOne in model

Hi i have set a user to haveOne application in the User model, How can i get filament to use the relationship so a user cannot create more than one application? Thanks
5 Replies
itsmejyv
itsmejyv4mo ago
define it to both model and make a validation
Cushty
CushtyOP4mo ago
Hi, can you elaborate on the make-validation? I have belongsTo and hasOne set up on both models, I have added this to the application resource, and it hides the create button, but if I manually go to the create page it just says forbidden, is there a way to redirect back to list view and show a notification?
public static function canCreate(): bool
{
return auth()->user()->application()->count() === 0 || auth()->user()->isAdmin();
}
public static function canCreate(): bool
{
return auth()->user()->application()->count() === 0 || auth()->user()->isAdmin();
}
thanks
itsmejyv
itsmejyv4mo ago
looks like you're trying to create a role base permission? https://filamentphp.com/plugins/bezhansalleh-shield
Filament
Shield by Bezhan Salleh - Filament
The easiest and most intuitive way to add access management to your Filament Panel's Resources, Pages & Widgets through spatie/laravel-permission.
Cushty
CushtyOP4mo ago
Thanks for the reply, is this the best way of setting up permissions? Will this sort out the manual create url access forbidden issue? Thanks mate
itsmejyv
itsmejyv4mo ago
yeah, you can also watch this tutorial: https://youtu.be/iOzkpKZnnI0?feature=shared
Tony Xhepa
YouTube
Laravel Filament Shield Plugin - Role and Permission
Secure Your Laravel Filament Admin Panel with Roles & Permissions This video dives into the Filament Shield plugin, the ultimate tool for managing roles and permissions in your Laravel Filament admin panel. Key Features: Effortless RBAC (Role-Based Access Control): Control user access to Resources, Pages, Widgets, and custom functionalities u...
Want results from more Discord servers?
Add your server