-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Description
Description
Hi,
I ran into an issue using givePermissionTo(). If I try to assign a permission that doesn’t exist in the database, it throws this error:
Spatie\Permission\Exceptions\PermissionDoesNotExist: There is no permission named
xyzfor guard
web.
This becomes a problem when assigning dynamic permissions (e.g., from a form or seed data) — I have to wrap every call in a try-catch, which makes the code messy.
Steps To Reproduce
1.A givePermissionIfExistsTo() method, or
2.A config option to skip missing permissions
Would love to hear your thoughts on this or if there's a better way to handle it.
Thanks for the great package!
Example Application
No response
Version of spatie/laravel-permission package:
6.11.0
Version of laravel/framework package:
10.42
PHP version:
8.2
Database engine and version:
MySQL 8.0
OS: Windows/Mac/Linux version:
Windows 11
parallels999, tusharnain and DrPowerSlam
Metadata
Metadata
Assignees
Labels
No labels