vendredi 1 mai 2015

Laravel 5 and Entrust. How to save user and attach role at the same time

has anyone tried Entrust for User Roles & Permissions in laravel 5?

i want to add and save user and attach role into it at the same time. here's my code

     $role = Role::where('name','=','admin')->first();
     $user = new User();
     $user->name = Input::get('name');
     $user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));
      if($user->save()){
          $user->attachRole($role);
          return redirect('dashboard/users')->with('success-message','New user has been added');
      }

But "$user->attachRole($role);" wont work though it works on my databaseSeeder but not on my UserController. Any help will be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire