refactor ClientDepartmentController and ClientFacultyController; replace caching logic with action classes for department and faculty retrieval, enhancing code clarity and maintainability
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Containers\InstituteStructure\Tasks;
|
||||
|
||||
use App\Containers\InstituteStructure\Models\Faculty;
|
||||
use App\Ship\Enums\CacheKeys;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class GetFacultyBySlugTask
|
||||
{
|
||||
public function run(string $slug): Faculty
|
||||
{
|
||||
return Cache::remember(
|
||||
CacheKeys::FACULTY_PREFIX->value . $slug,
|
||||
now()->addDay(),
|
||||
function () use ($slug) {
|
||||
return Faculty::where('slug', $slug)
|
||||
->where('is_active', true)
|
||||
->with(['departments.faculty',
|
||||
'workers' => fn ($query) => $query->orderBy('sort', 'asc'),
|
||||
'workers.userDetail',
|
||||
'seo'
|
||||
])
|
||||
->firstOrFail();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user