get(); } public function role() { return $this->hasOne('App\Models\UserRole', 'character_id'); } public function permissions() { return $this->hasMany('App\Models\UserPermission', 'character_id'); } public function esitoken() { return $this->hasOne('App\Models\EsiToken', 'character_id', 'character_id'); } public function hasPermission($permission) { //Check if the user has a specific permission if(UserPermission::where(['character_id' => $this->character_id, 'permission' => $permission])->get()) { return true; } else { return false; } } public function hasRole($role, $permission = true) { //If the user is a super user then he has all roles if($this->hasSuperUser()) { return true; } if(UserRole::where(['character_id' => $this->character_id, 'role' => $role])->get()) { //Check for inverse permissions if($permission === true) { return true; } else { return false; } } else { //Check for inverse permissions if($permission === true) { return true; } else { return false; } } } public function hasSuperUser() { //Search for the super user role for the character from the database $found = DB::table('user_roles')->where(['character_id' => $this->character_id, 'role' => 'SuperUser'])->get(['role']); //If we find the SuperUser role, then the user has it, and returns true, else returns false if($found == 'SuperUser') { return true; } else { return false; } } }