Exemplo n.º 1
0
 /**
  * Helper function to get role id by name
  *
  * @param string $name Role name.
  *
  * @return boolean|integer Returns id or false.
  */
 public static function getRoleId($name)
 {
     try {
         $role = Role::where('name', $name)->firstOrFail();
         return $role->id;
     } catch (Exception $e) {
         return false;
     }
 }
Exemplo n.º 2
0
 /**
  * Determine if the given user has the requested role.
  *
  * @param string $name Role name.
  *
  * @return boolean
  */
 public function hasRole($name)
 {
     $role_id = Role::getRoleId($name);
     try {
         RoleMember::where('user_id', $this->id)->where('role_id', $role_id)->firstOrFail();
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Exemplo n.º 3
0
 public function run()
 {
     foreach ($this->roles as $role) {
         Role::create(['name' => $role]);
     }
 }
Exemplo n.º 4
0
 /**
  * Get the role id
  * @return string $role_id
  */
 public function getRoleId()
 {
     $roles = Role::all();
     $roleData = $this->buildRoleTable($roles);
     $this->table(['id', 'role'], $roleData);
     $role_id = $this->ask('Which role would you like to assign to the user? [1,2,...]');
     return $role_id;
 }