Роли, переделывание отчета, изменение на главной странице
This commit is contained in:
@@ -5,6 +5,9 @@ namespace App\Models;
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -55,49 +58,60 @@ class User extends Authenticatable
|
||||
return $this->belongsTo(Department::class, 'rf_department_id');
|
||||
}
|
||||
|
||||
public function userRoles(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserRole::class, 'rf_user_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Role::class,
|
||||
UserRole::class,
|
||||
'rf_user_id',
|
||||
'role_id',
|
||||
'id',
|
||||
'rf_role_id'
|
||||
);
|
||||
}
|
||||
|
||||
public function currentRole()
|
||||
{
|
||||
$defaultRoleId = $this->roles()->where('is_default', true)->first()->role_id;
|
||||
$roleId = session('currentRoleId', $defaultRoleId);
|
||||
|
||||
$role = Role::where('role_id', $roleId)->first();
|
||||
|
||||
return $role;
|
||||
}
|
||||
|
||||
// Методы для проверки ролей
|
||||
public function isAdmin()
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
return $this->currentRole()->slug === 'admin';
|
||||
}
|
||||
|
||||
public function isDoctor()
|
||||
{
|
||||
return $this->role === 'doctor';
|
||||
}
|
||||
|
||||
public function isNurse()
|
||||
{
|
||||
return $this->role === 'nurse';
|
||||
return $this->currentRole()->slug === 'doctor';
|
||||
}
|
||||
|
||||
public function isHeadOfDepartment()
|
||||
{
|
||||
return $this->role === 'head_of_department';
|
||||
return $this->currentRole()->slug === 'head_of_department';
|
||||
}
|
||||
|
||||
public function isStatistician()
|
||||
{
|
||||
return $this->role === 'statistician';
|
||||
return $this->currentRole()->slug === 'statistician';
|
||||
}
|
||||
|
||||
// Получение доступных отделений
|
||||
public function availableDepartments()
|
||||
{
|
||||
$departments = [
|
||||
'Гематология',
|
||||
'Хирургия',
|
||||
'Терапия',
|
||||
'Реанимация',
|
||||
'Онкология',
|
||||
'Кардиология',
|
||||
'Неврология',
|
||||
'Урология',
|
||||
'Гинекология',
|
||||
'Лаборатория'
|
||||
];
|
||||
$departments = Department::all();
|
||||
|
||||
if ($this->isAdmin() || $this->isHeadOfDepartment()) {
|
||||
if ($this->isAdmin()) {
|
||||
return $departments;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user