Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

uusa35's avatar

Entrust Roles & Permission Routes

hi guys , straight forward to the issue

i am using Entrust package for roles and permissions :

the thing is i made a middleware that will fetch the role of the authenticated user and then will fetch all permissions related to the user.

do you have any ideas how to set up routes dynamically ? !

meaning : Editor Role -> edit-books Permission -> then to generate the route for books dynamically

how can i create routes that are generated dynamically for each permission.

0 likes
1 reply
thomaskim's avatar

@uusa35 I'm not sure I completely understand your question. You can use route groups to add a middleware to an entire group of routes so that you don't have to keep manually adding one:

http://laravel.com/docs/master/routing#route-groups

Example:

Route::group(['middleware' => 'CustomAuth'], function () {
        // All routes inside this group now uses the CustomAuth middleware

    Route::get('/', function ()    {
        // Uses CustomAuth Middleware
    });

    Route::get('user/profile', function () {
        // Uses CustomAuth Middleware
    });
});

Please or to participate in this conversation.