diff --git a/app/Containers/Dashboard/Actions/Departments/ListDepartmentTeachersAction.php b/app/Containers/Dashboard/Actions/Departments/ListDepartmentTeachersAction.php index 2a09716..27661a7 100644 --- a/app/Containers/Dashboard/Actions/Departments/ListDepartmentTeachersAction.php +++ b/app/Containers/Dashboard/Actions/Departments/ListDepartmentTeachersAction.php @@ -17,7 +17,7 @@ class ListDepartmentTeachersAction // Фильтр по должности if (!empty($filters['position'])) { - $query->where('teaching_position', 'like', '%' . $filters['position'] . '%'); + $query->wherePivot('teaching_position', 'like', '%' . $filters['position'] . '%'); } $teachers = $query->orderBy('teachers_departments.sort')->paginate(20)->withQueryString(); diff --git a/app/Containers/Dashboard/Actions/Departments/ListDepartmentWorkersAction.php b/app/Containers/Dashboard/Actions/Departments/ListDepartmentWorkersAction.php index 39635e0..cefc45d 100644 --- a/app/Containers/Dashboard/Actions/Departments/ListDepartmentWorkersAction.php +++ b/app/Containers/Dashboard/Actions/Departments/ListDepartmentWorkersAction.php @@ -18,7 +18,7 @@ class ListDepartmentWorkersAction // Фильтр по должности if (!empty($filters['position'])) { - $query->where('position', 'like', '%' . $filters['position'] . '%'); + $query->wherePivot('position', 'like', '%' . $filters['position'] . '%'); } $workers = $query->orderBy('workers_departments.sort')->paginate(20)->withQueryString(); diff --git a/app/Containers/User/Models/User.php b/app/Containers/User/Models/User.php index 3d0dca7..5863a71 100755 --- a/app/Containers/User/Models/User.php +++ b/app/Containers/User/Models/User.php @@ -12,7 +12,7 @@ use BezhanSalleh\FilamentShield\Support\Utils; use BezhanSalleh\FilamentShield\Traits\HasPanelShield; use Filament\Models\Contracts\FilamentUser; use Filament\Tables\Columns\Layout\Panel; -use Illuminate\Database\Eloquent\Factories\HasFactory; +use App\Ship\Traits\HasContainerFactory; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; @@ -23,7 +23,9 @@ use Spatie\Permission\Traits\HasRoles; class User extends Authenticatable implements FilamentUser, SeoTitleInterface, SeoDescriptionInterface { - use HasApiTokens, HasFactory, Notifiable, HasRoles, HasPanelShield, HasSeo; + use HasApiTokens, HasContainerFactory, Notifiable, HasRoles, HasPanelShield, HasSeo; + + protected static string $factory = \Database\Factories\UserFactory::class; /** * The attributes that are mass assignable. @@ -65,12 +67,14 @@ class User extends Authenticatable implements FilamentUser, SeoTitleInterface, S public function departments_work(): BelongsToMany { - return $this->belongsToMany(Department::class, 'workers_departments')->withPivot(['position']); + 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']); + return $this->belongsToMany(Department::class, 'teachers_departments') + ->withPivot(['teaching_position', 'sort', 'service_email', 'service_phone', 'cabinet']); } public function divisions(): BelongsToMany diff --git a/app/Filament/Resources/DepartmentResource/RelationManagers/TeachersRelationManager.php b/app/Filament/Resources/DepartmentResource/RelationManagers/TeachersRelationManager.php index d512b54..6be0a79 100755 --- a/app/Filament/Resources/DepartmentResource/RelationManagers/TeachersRelationManager.php +++ b/app/Filament/Resources/DepartmentResource/RelationManagers/TeachersRelationManager.php @@ -70,18 +70,18 @@ class TeachersRelationManager extends RelationManager ->searchable() ->sortable(), - Tables\Columns\TextColumn::make('teaching_position') + Tables\Columns\TextColumn::make('pivot.teaching_position') ->label('Должность') ->searchable() ->sortable() ->wrap(), - Tables\Columns\TextColumn::make('service_email') + Tables\Columns\TextColumn::make('pivot.service_email') ->label('Почта') ->searchable() ->toggleable(isToggledHiddenByDefault: true), - Tables\Columns\TextColumn::make('cabinet') + Tables\Columns\TextColumn::make('pivot.cabinet') ->label('Кабинет') ->sortable() ->toggleable(), @@ -144,14 +144,20 @@ class TeachersRelationManager extends RelationManager ->actions([ Tables\Actions\EditAction::make() ->iconButton() - ->tooltip('Редактировать'), + ->tooltip('Редактировать') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), Tables\Actions\DetachAction::make() ->iconButton() ->tooltip('Убрать с кафедры') ->modalHeading('Удаление связи') ->modalSubmitActionLabel('Убрать') - ->modalDescription('Вы уверены, что хотите убрать этого преподавателя с кафедры?'), + ->modalDescription('Вы уверены, что хотите убрать этого преподавателя с кафедры?') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ @@ -159,7 +165,10 @@ class TeachersRelationManager extends RelationManager ->label('Убрать выбранных') ->modalHeading('Удаление связей') ->modalSubmitActionLabel('Убрать') - ->modalDescription('Вы уверены, что хотите убрать выбранных преподавателей с кафедры?'), + ->modalDescription('Вы уверены, что хотите убрать выбранных преподавателей с кафедры?') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), ]), ]) ->emptyStateActions([ diff --git a/app/Filament/Resources/DepartmentResource/RelationManagers/WorkersRelationManager.php b/app/Filament/Resources/DepartmentResource/RelationManagers/WorkersRelationManager.php index 8347851..9604a0d 100755 --- a/app/Filament/Resources/DepartmentResource/RelationManagers/WorkersRelationManager.php +++ b/app/Filament/Resources/DepartmentResource/RelationManagers/WorkersRelationManager.php @@ -70,18 +70,18 @@ class WorkersRelationManager extends RelationManager ->searchable() ->sortable(), - Tables\Columns\TextColumn::make('position') + Tables\Columns\TextColumn::make('pivot.position') ->label('Должность') ->searchable() ->sortable() ->wrap(), - Tables\Columns\TextColumn::make('service_email') + Tables\Columns\TextColumn::make('pivot.service_email') ->label('Почта') ->searchable() ->toggleable(isToggledHiddenByDefault: true), - Tables\Columns\TextColumn::make('cabinet') + Tables\Columns\TextColumn::make('pivot.cabinet') ->label('Кабинет') ->sortable() ->toggleable(), @@ -144,14 +144,20 @@ class WorkersRelationManager extends RelationManager ->actions([ Tables\Actions\EditAction::make() ->iconButton() - ->tooltip('Редактировать'), + ->tooltip('Редактировать') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), Tables\Actions\DetachAction::make() ->iconButton() ->tooltip('Убрать с кафедры') ->modalHeading('Удаление связи') ->modalSubmitActionLabel('Убрать') - ->modalDescription('Вы уверены, что хотите убрать этого сотрудника с кафедры?'), + ->modalDescription('Вы уверены, что хотите убрать этого сотрудника с кафедры?') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ @@ -159,7 +165,10 @@ class WorkersRelationManager extends RelationManager ->label('Убрать выбранных') ->modalHeading('Удаление связей') ->modalSubmitActionLabel('Убрать') - ->modalDescription('Вы уверены, что хотите убрать выбранных сотрудников с кафедры?'), + ->modalDescription('Вы уверены, что хотите убрать выбранных сотрудников с кафедры?') + ->before(function () { + app(DepartmentCacheService::class)->clearAllCacheByModel(); + }), ]), ]) ->emptyStateActions([ diff --git a/app/Services/App/Cache/DepartmentCacheService.php b/app/Services/App/Cache/DepartmentCacheService.php index 65e1f12..6c8ca5a 100755 --- a/app/Services/App/Cache/DepartmentCacheService.php +++ b/app/Services/App/Cache/DepartmentCacheService.php @@ -21,6 +21,7 @@ class DepartmentCacheService extends AbstractCacheService implements CacheInterf { $this->clearCacheByPrefix(CacheKeys::DEPARTMENT_PREFIX->value.'*'); $this->clearCacheByPrefix(CacheKeys::DEPARTMENTS_PREFIX->value.'*'); + $this->clearCacheByPrefix(CacheKeys::USER_PREFIX->value.'*'); } public function getCachedData(string $key) diff --git a/resources/js/Pages/Dashboard/Departments/Teachers/Index.vue b/resources/js/Pages/Dashboard/Departments/Teachers/Index.vue index ccb521d..2ab3bcb 100644 --- a/resources/js/Pages/Dashboard/Departments/Teachers/Index.vue +++ b/resources/js/Pages/Dashboard/Departments/Teachers/Index.vue @@ -41,7 +41,11 @@ - {{ teacher.name }} + {{ teacher.name }} {{ teacher.pivot.teaching_position }} @@ -124,6 +128,7 @@ {{ user.name }} +

{{ $page.props.errors.user_id }}

@@ -138,6 +143,7 @@ placeholder="Например: Профессор" class="w-full px-3 py-2 border border-layer-line rounded-lg bg-white text-foreground placeholder-muted-foreground-1 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" /> +

{{ $page.props.errors.teaching_position }}

@@ -152,6 +158,7 @@ placeholder="example@university.ru" class="w-full px-3 py-2 border border-layer-line rounded-lg bg-white text-foreground placeholder-muted-foreground-1 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" /> +

{{ $page.props.errors.service_email }}

@@ -165,6 +172,7 @@ placeholder="+7 (XXX) XXX-XX-XX" class="w-full px-3 py-2 border border-layer-line rounded-lg bg-white text-foreground placeholder-muted-foreground-1 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" /> +

{{ $page.props.errors.service_phone }}

@@ -179,6 +187,7 @@ placeholder="Например: 305а" class="w-full px-3 py-2 border border-layer-line rounded-lg bg-white text-foreground placeholder-muted-foreground-1 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" /> +

{{ $page.props.errors.cabinet }}

@@ -205,11 +214,13 @@