From 1df1a1390fc8be0e0e6ff3b2bfc35ce145cafd54 Mon Sep 17 00:00:00 2001 From: F4ilji Date: Wed, 23 Apr 2025 20:45:25 +0500 Subject: [PATCH] fix bugs --- .../ClientAdditionalEducationController.php | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/ClientAdditionalEducationController.php b/app/Http/Controllers/ClientAdditionalEducationController.php index f2fa928..24dd55f 100644 --- a/app/Http/Controllers/ClientAdditionalEducationController.php +++ b/app/Http/Controllers/ClientAdditionalEducationController.php @@ -50,26 +50,23 @@ class ClientAdditionalEducationController extends Controller function () use ($request) { $query = AdditionalEducationCategory::query() ->has('additionalEducations') - ->WithActivePrograms() - ->where('is_active', true) - ->when($request->input('form'), function ($q, $form) { - $formValue = FormEducation::fromName($form)->value; - $q->whereHas('additionalEducations', fn ($q) => $q->where('form_education', $formValue)) - ->with(['additionalEducations' => fn ($q) => $q->where('form_education', $formValue)]); - }) - ->when($request->input('category'), function($q, $slugs) { - $q->whereIn('slug', $slugs); - }) - ->when($request->direction, function ($q, $direction) use ($request) { - return $q->whereHas('direction', fn($query) => $query->where('slug', $direction)) - ->when($request->form, fn($query, $form) => $query->whereHas('additionalEducations', fn($q) => $q->where('form_education', FormEducation::fromName($form)) - ) - ->when($request->category, fn($query) => is_array($request->category) - ? $query->whereIn('slug', $request->category) - : $query->where('slug', $request->category) - ) - ->has('additionalEducations')); - }); + ->withActivePrograms() + ->where('is_active', true); + + if ($request->has('form')) { + $formValue = FormEducation::fromName($request->form)->value; + $query->whereHas('additionalEducations', fn ($q) => $q->where('form_education', $formValue)) + ->with(['additionalEducations' => fn ($q) => $q->where('form_education', $formValue)]); + } + + if ($request->has('category')) { + $slugs = is_array($request->category) ? $request->category : [$request->category]; + $query->whereIn('slug', $slugs); + } + + if ($request->has('direction')) { + $query->whereHas('direction', fn($q) => $q->where('slug', $request->direction)); + } return AdditionalEducationCategoryResource::collection($query->get()); }