/** * Run the database seeds. * * @return void */ public function run() { \DB::table('roles')->truncate(); $roles = [['name' => 'login', 'description' => 'Login privileges, granted after account confirmation.'], ['name' => 'administrator', 'description' => 'Administrative user, has access to everything.'], ['name' => 'developer', 'description' => '']]; foreach ($roles as $data) { UserRole::create($data); } }
public function getEdit($filename) { $file = $this->getFile($filename); $roles = UserRole::lists('name', 'name'); $this->setTitle(trans("{$this->moduleNamespace}{$this->sectionPrefix}.title.edit", ['name' => $file->getName()])); $this->templateScripts['FILE'] = $file->toArray(); $this->setContent("{$this->sectionPrefix}.edit", compact('file', 'roles')); }
/** * @param integer $id * @return UserRole * @throws HttpResponseException */ protected function getRole($id) { try { return UserRole::findOrFail($id); } catch (ModelNotFoundException $e) { $this->throwFailException($this->smartRedirect()->withErrors(trans('users::role.messages.not_found'))); } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { $role = UserRole::create(array_only($data, ['name', 'description'])); if (isset($data['permissions'])) { $permissions = (array) $data['permissions']; $role->attachPermissions($permissions); } return $role; }
/** * Create a new user instance after a valid registration. * * @param integer $id * @param array $data * @return User */ public function update($id, array $data) { $role = UserRole::findOrFail($id); $role->update(array_only($data, ['name', 'description'])); if ($role->id > 2 and isset($data['permissions'])) { $permissions = (array) $data['permissions']; $role->attachPermissions($permissions); } return $role; }
public function boot() { User::observe(new UserObserver()); UserRole::observe(new RoleObserver()); Event::listen('view.navbar.right.after', function () { echo view('users::parts.navbar'); }); Event::listen('view.menu.before', function () { echo view('users::parts.navigation'); }); }
/** * Run the database seeds. * * @return void */ public function run() { \DB::table('users')->truncate(); \DB::table('roles_users')->truncate(); $roles = UserRole::get()->lists('id'); $maxRolesToAtach = count($roles) > 4 ? 4 : count($roles); $faker = \Faker\Factory::create(); $totalUsers = 50; $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'username' => 'admin']); $user->roles()->sync([1, 2, 3]); $usedEmails = $usedUsernames = []; for ($i = 0; $i < $totalUsers; $i++) { do { $email = strtolower($faker->email); } while (in_array($email, $usedEmails)); $usedEmails[] = $email; do { $username = strtolower($faker->userName); } while (in_array($username, $usedUsernames)); $usedUsernames[] = $username; $user = User::create(['email' => $email, 'password' => 'password', 'username' => $username, 'locale' => $faker->randomElement(['ru', 'en'])]); $user->roles()->attach($faker->randomElements($roles, rand(1, $maxRolesToAtach))); } }
/** * @param UserRole $role * @param string $message * @param NotificationTypeInterface|null $type * @param array $parameters */ public function __construct(UserRole $role, $message = null, NotificationTypeInterface $type = null, array $parameters = []) { parent::__construct($role->users()->lists('id')->all(), $message, $type, $parameters); }
/** * @param \KodiCMS\Users\Model\UserRole $role * @return bool */ public function deleted($role) { $role->permissions()->delete(); }
public function getAll() { $this->setContent(UserRole::get()); }