spatie/laravel-permission There is no permission named `edit_project` for guard `api`

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Resolving Issues With spatie/laravel-permission and guard 'api' Introduction: Spatie/Laravel-Permission is a comprehensive package for managing permissions in your Laravel application. However, if you face issues with assigning specific permissions to a certain guard such as "edit_project" for the guard "api", don't worry. This article will help you understand and resolve these issues by providing insightful information about configuring authentication settings, dealing with permission table structures, handling guard names in your application, and making the best use of Laravel seeder to organize permissions effectively. 1. Authentication Configuration: Ensure that your Laravel configuration file (config/auth.php) is correctly configured for both guards "web" and "api". The auth.php file should include appropriate values for 'guard', 'driver', and 'provider'. This allows you to separate your authentication logic based on the incoming request. In case of any discrepancies, modify the configuration as needed. 2. Permission Table Structure: Ensure that your permission table has a column named 'guard_name' with proper values for each guard (web or api) - this is essential when using multiple guards and assigning permissions to specific ones. The correct guard name helps spatie/laravel-permission package to retrieve the appropriate permissions for the selected guard. 3. Check Role Assignment: Verify that you are assigning roles properly, especially when working with Laravel seeder. Each role should have a unique name and the correct guard_name associated with it. Make sure that you have assigned your roles before seeding. Incorrect assignment of roles can lead to confusion in the permission table structure. 4. Seeder Implementation: If you're using Laravel seeder, make sure to set up appropriate role assignments. You could create a single seeder for every guard or separate ones based on your application logic. This allows you to manage permissions for each guard effectively with proper access control. 5. Permission Naming Conventions: Be consistent in naming your permission names across guards. For example, if "edit_project" is an existing permission name assigned to the web guard, ensure that you don't create a new permission named "edit_project" for the api guard. In this case, consider renaming it as "api_edit_project". Consistency in naming conventions helps prevent confusion in your application and ensures proper permission assignments across guards. 6. Database Migration: Always run database migrations properly and ensure that you have a clean migration history. Any inconsistencies or incorrectly applied migrations can cause issues with the permissions table structure, leading to unexpected behavior while assigning roles to users. Conclusion: By following these suggestions, you will be able to successfully manage your permission settings across different guards in your Laravel application. It is crucial to have a clean and well-organized set of configuration files, role assignments, and seeder implementation for optimal performance. Remember that effective organization and communication between your development team can help alleviate these issues, leading to smoother workflows and better project management overall.