Exemplo n.º 1
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.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $user_id = $this->getUserId();
     } catch (Exception $e) {
         return $this->line("Error user specified is invalid");
     }
     try {
         $role_id = $this->getRoleId();
     } catch (Exception $e) {
         return $this->line("Error user specified is invalid");
     }
     try {
         RoleMember::create(['user_id' => $user_id, 'role_id' => $role_id]);
     } catch (Exception $e) {
         \Log::debug($e->getMessage());
         $this->line("Unable to add user to role");
     }
     /* Get list of roles */
     $this->line("User {$user_id} added to role {$role_id}");
 }