authorization

Enforce role-based access control for Laravel 12 backend routes.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/taucao-ruby/soleil-hostel --skill authorization
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: authorization
Source: https://github.com/taucao-ruby/soleil-hostel/tree/main/.claude/skills/generated/authorization
Command: npx skills add https://github.com/taucao-ruby/soleil-hostel --skill authorization

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Manages and enforces role-based access control for the Soleil Hostel backend, ensuring only authorized users can access admin and moderator functionality and protected routes.

Core Features & Use Cases

  • Role definitions and permission checks via hasRole and isUser helpers.
  • Gate and middleware enforcement for admin and moderator routes.
  • Test coverage across unit and feature tests (GateTest, EnsureUserHasRoleTest, UserRoleHelpersTest) to validate access rules.
  • Factory setup for admin and moderator states to support reproducible tests.

Quick Start

Review the backend authorization flow by inspecting Gate, EnsureUserHasRole, and User model tests to extend or modify access rules.

Frequently Asked Questions about authorization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up role-based access control in a Laravel backend?

Role-based access control in Laravel is implemented here using Gates and middleware to enforce permissions for admin and moderator routes. It defines role enums and applies EnsureUserHasRole middleware to restrict access to protected backend functionality.

How do I test authorization gates and middleware in Laravel?

You test authorization gates and middleware using dedicated test suites like GateTest, EnsureUserHasRoleTest, and UserRoleHelpersTest. These validate access rules by leveraging UserFactory role states to generate admin and moderator users for reproducible unit and integration tests.

Do I need Laravel 12 to use this role-based access control implementation?

Yes, this role-based access control implementation requires Laravel 12 running on PHP 8.2 or higher. It relies on framework-specific features like Gates, role enums, and middleware to enforce permissions for admin and moderator users.

What is the best way to check user permissions for admin routes in Laravel?

The best way to check user permissions for admin routes is using hasRole and isUser helpers alongside Laravel Gates. This approach enforces role-based access control by verifying user roles before granting access to protected moderator and admin functionality.

How do I create admin and moderator users for testing Laravel authorization?

You create admin and moderator users for testing Laravel authorization by using UserFactory role states. These factory states generate users with specific roles to support reproducible unit and integration tests for your access control rules.

Why does my Laravel middleware return unauthorized for admin users?

Laravel middleware returns unauthorized when role-based access control rules fail to validate the user. Ensure your EnsureUserHasRole middleware correctly checks hasRole helpers, role enums are accurate, and GateTest coverage validates the expected admin permissions.