How to modify routing or change module url format?



  • Once installed, we can access to modules with http://localhost/cms/public/en/backend/user/users/1/edit for example if we want to edit a user details, same go to other action.

    My question is , is there possible we can modify the routing so we can change the url to http://localhost/cms/public/en/backend/users/1/edit ? I tried to change in backend route by remove the prefix. but then I get NotFoundHttpException error.


  • Global Moderator

    @esien525

    Hey, yes you can do that. Assuming you have not modified default installation.
    a) Remove route group altogether
    b) Supply empty array

    Tested this on v2 just now.



  • @armababy , can u guide me with more details? if i remove the prefix from group, how should I edit the default route set in other page (e.g in sidebar $item->route('admin.user.user.index');), manually one by one? I'm using v1.


  • Global Moderator

    @esien525
    You don't have to rename anything, routes everywhere are named ones.
    So even if it's called admin.user.user.index it should point to backend/users

    With this $router->group([], function (Router $router) { as a group



  • @armababy , I can access backend/users by modify the permission from user.users.index to users.dashboard.index. But I cant edit the user, I get Permission denied. (required permission: "users.1.edit"). Below was my route setting

    $router->group([], function (Router $router) {
        $router->get('users', ['as' => 'admin.user.user.index', 'uses' => 'UserController4']);
        $router->get('users/create', ['as' => 'admin.user.user.create', 'uses' => 'UserController@create']);
        $router->post('users', ['as' => 'admin.user.user.store', 'uses' => 'UserController@store']);
        $router->get('users/{users}/edit', ['as' => 'admin.user.user.edit', 'uses' => 'UserController@edit']);
        $router->put('users/{users}/edit', ['as' => 'admin.user.user.update', 'uses' => 'UserController@update']);
        $router->get('users/{users}/sendResetPassword', ['as' => 'admin.user.user.sendResetPassword', 'uses' => 'UserController@sendResetPassword']);
        $router->delete('users/{users}', ['as' => 'admin.user.user.destroy', 'uses' => 'UserController@destroy']);
    
        $router->get('roles', ['as' => 'admin.user.role.index', 'uses' => 'RolesController4']);
        $router->get('roles/create', ['as' => 'admin.user.role.create', 'uses' => 'RolesController@create']);
        $router->post('roles', ['as' => 'admin.user.role.store', 'uses' => 'RolesController@store']);
        $router->get('roles/{roles}/edit', ['as' => 'admin.user.role.edit', 'uses' => 'RolesController@edit']);
        $router->put('roles/{roles}/edit', ['as' => 'admin.user.role.update', 'uses' => 'RolesController@update']);
        $router->delete('roles/{roles}', ['as' => 'admin.user.role.destroy', 'uses' => 'RolesController@destroy']);
    });
    

    default permission

    {"user.users.index":true,"user.users.create":true,"user.users.store":true,"user.users.edit":true,"user.users.update":true,"user.users.destroy":true,"user.roles.index":true,"user.roles.create":true,"user.roles.store":true,"user.roles.edit":true,"user.roles.update":true,"user.roles.destroy":true}
    

  • Global Moderator

    @esien525 You should then try and update User permissions.php config file.

    <?php
    return [
        'users' => [
            'index',
            'create',
            'store',
            'edit',
            'update',
            'destroy',
            'sendResetPassword',
        ],
        'roles' => [
            'index',
            'create',
            'store',
            'edit',
            'update',
            'destroy',
        ],
    ];
    

    And then update permissions for a user or a role.



  • @armababy , I still cant make it worked. Same error on edit user. I need to manually set the id in database permission for users/{id}/edit. I think for now I will just use the default way.


Log in to reply
 

Looks like your connection to AsgardCms was lost, please wait while we try to reconnect.