/** * Run the database seeds. * * @return void */ public function run() { $users = [['user', '*****@*****.**', 'user'], ['admin', '*****@*****.**', 'admin']]; foreach ($users as $user) { User::create(['username' => $user[0], 'email' => $user[1], 'password' => \Hash::make($user[2])]); } }
/** * Run the database seeds. * * @return void */ public function run() { User::whereUsername('admin')->first()->assignRole(Role::whereName('admin')->first()); User::whereUsername('user')->first()->assignRole(Role::whereName('user')->first()); }
/** * return all available role for this user * * @param User $user * @return array */ public function getRolesFor(User $user) { $userRoles = $user->roles()->get(); $roles = Role::where('order', '<=', $this->maxRole()->order); foreach ($userRoles as $role) { $roles = $roles->where('name', '!=', $role->name); } return $roles->get(); }