sergionc
2 months ago
280
1
Laravel

default role for new users

Posted 2 months ago by sergionc

Applying the spatie permission package, to each new registered user that has a default role.

Default function of creating users:

protected function create(array $data)

{ return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'nacimiento' => $data['nacimiento'], 'sexo' => $data['sexo'] ]); }

I tried something like:

$user = User::latest('id')->first();

$user->hasRole('visita');

Please sign in or create an account to participate in this conversation.