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

Duffman88's avatar

How to award roles to users?

So i was following https://laracasts.com/series/laravel-6-from-scratch/episodes/54?autoplay=true where Jeff talked about Roles and Abilities, but now i wonder. How to make it more user friendly? To call method from like admin panel, so i dont have to use tinker? Do users automatically get role as they register? And how to make yourself admin, since only admin can give you roles (if you know what i mean?), do you do that directly on database?

0 likes
2 replies
frankielee's avatar

Maybe you can do some checking on registration,

Example :

  1. If the users' table is empty, the first registered user will grant the super admin permission.

  2. The rest users will register as basic users.

  3. Only super admin and admin can create or promote users to admin.

Duffman88's avatar

Well i did notice

protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }

So I`m thinking that maybe here I could give them some basic role, or maybe they dont even need role. As long as they are just registered users.

Please or to participate in this conversation.