Files
F4ilji bf77cb634c fix(departments): fix contact info editing, cache invalidation, and pivot data display
- User model: add missing pivot columns (service_email, service_phone, cabinet, sort) to departments_work() and departments_teach() withPivot
- ListDepartmentWorkersAction/TeachersAction: fix where() to wherePivot() for position filters
- Dashboard Workers/Teachers Index.vue: display validation errors in add/edit modals
- Dashboard Workers/Teachers Index.vue: add links to client person pages
- DepartmentCacheService: clear person_* cache when department data changes
- Filament WorkersRelationManager/TeachersRelationManager: fix pivot columns in table (pivot.position etc), add cache clearing on edit/detach/bulk actions
2026-09-18 01:32:27 +05:00

125 lines
3.8 KiB
PHP
Executable File

<?php
namespace App\Containers\User\Models;
use App\Containers\InstituteStructure\Models\Department;
use App\Containers\InstituteStructure\Models\Division;
use App\Containers\InstituteStructure\Models\Faculty;
use App\Ship\Contracts\SeoDescriptionInterface;
use App\Ship\Contracts\SeoTitleInterface;
use App\Ship\Traits\HasSeo;
use BezhanSalleh\FilamentShield\Support\Utils;
use BezhanSalleh\FilamentShield\Traits\HasPanelShield;
use Filament\Models\Contracts\FilamentUser;
use Filament\Tables\Columns\Layout\Panel;
use App\Ship\Traits\HasContainerFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable implements FilamentUser, SeoTitleInterface, SeoDescriptionInterface
{
use HasApiTokens, HasContainerFactory, Notifiable, HasRoles, HasPanelShield, HasSeo;
protected static string $factory = \Database\Factories\UserFactory::class;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'slug',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
public function userDetail(): HasOne
{
return $this->hasOne(UserDetail::class, 'user_id');
}
public function departments_work(): BelongsToMany
{
return $this->belongsToMany(Department::class, 'workers_departments')
->withPivot(['position', 'sort', 'service_email', 'service_phone', 'cabinet']);
}
public function departments_teach(): BelongsToMany
{
return $this->belongsToMany(Department::class, 'teachers_departments')
->withPivot(['teaching_position', 'sort', 'service_email', 'service_phone', 'cabinet']);
}
public function divisions(): BelongsToMany
{
return $this->belongsToMany(Division::class, 'division_user')->withPivot(['administrativePosition']);
}
public function faculties(): BelongsToMany
{
return $this->belongsToMany(Faculty::class, 'workers_faculties')->withPivot(['position']);
}
// Отношение к отправленным приглашениям
public function sentInvitations(): HasMany
{
return $this->hasMany(AcceptedInvitation::class, 'sender_id');
}
// Отношение к полученным приглашениям
public function receivedInvitation(): HasOne
{
return $this->hasOne(AcceptedInvitation::class, 'receiver_id');
}
public function canAccessPanel(Panel|\Filament\Panel $panel): bool
{
return match ($panel->getId()) {
"admin", "dashboard" => $this->hasRole(config('filament-shield.dashboard_user.name', 'dashboard_user'))
|| $this->hasRole(Utils::getSuperAdminName())
|| $this->hasRole(config('filament-shield.invited_user.name', 'invited_user')),
default => false,
};
}
public function getSeoTitle(): string
{
return $this->name;
}
public function getSeoDescription(): array
{
$text = 'Персональная страница сотрудника - ' . $this->name;
return $this->prepareDescription($text);
}
}