Files
ntspi-app/app/Containers/Dashboard/Actions/Departments/ListDepartmentWorkersAction.php
T
2026-04-07 17:54:26 +05:00

32 lines
873 B
PHP

<?php
namespace App\Containers\Dashboard\Actions\Departments;
use App\Containers\InstituteStructure\Models\Department;
use App\Containers\User\Models\User;
class ListDepartmentWorkersAction
{
public function run(Department $department, array $filters = []): array
{
$query = $department->workers();
// Поиск по имени
if (!empty($filters['search'])) {
$query->where('name', 'like', '%' . $filters['search'] . '%');
}
// Фильтр по должности
if (!empty($filters['position'])) {
$query->where('position', 'like', '%' . $filters['position'] . '%');
}
$workers = $query->orderBy('workers_departments.sort')->paginate(20)->withQueryString();
return [
'workers' => $workers,
'filters' => $filters,
];
}
}