Laravel

Allowing Geekshop admin to change role assigned to a user

This guide will allow you to change the role that has been assigned to a user.

In the current default setup of GeekShop (application by DevDojo) it is not possible to change the role assigned to a user. This means that you cannot select another user to be administrator of your GeekShop application.

How to do that?

First we will allow everyone to change the role assigned for a user, in order to do this go to Tools > Database in the admin menu. On that page you must find the users table and select Edit BREAD.

Now you will see a page with a lot of settings about how Voyager (the admin panel) handles CRUD'ing the users table. What you will need to do is to scroll down to the role_id field and set the following options for that field. Change User Role In Geekshop

Once that is done change the Model Name to be App\User and then hit save.

Now you will see a error if you go visit the users page. This is because the BREAD settings requires a relation to be made in the User model.

So open op app/User.php and add the following function:

    public function roleId()
    {
        return $this->role();
    }

Once that is done you will now see the list over users again (without a error message this time). Besides that you will now be able to edit the role assigned to a user.

Mark Topper Diderichsen

Strong minded, full-stack web developer with passion for performance and scalability and with a flair for building elegant solutions for advanced platforms. Available for freelancing and consultancy at Ulties Company.

Related Posts