diff --git a/app/Http/Controllers/Bo/ClaimController.php b/app/Http/Controllers/Bo/ClaimController.php index 9d27306..5f97d85 100644 --- a/app/Http/Controllers/Bo/ClaimController.php +++ b/app/Http/Controllers/Bo/ClaimController.php @@ -99,13 +99,23 @@ class ClaimController extends Controller /** Custom pagination */ $claimModels = $query->simplePaginate($this->getPagination()); + /** Define request brand filter if user only has 1 brand */ + if (auth('backend')->user()->brands()->count() === 1) { + $request->merge(['brand' => auth('backend')->user()->brands()->value('id')]); + }; + $claimSubjectModels = ClaimSubject::query() ->when( $request->filled('brand'), fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand)), - fn($q) => $q->whereHas('brand', fn($q) => $q->whereIn('id', $userModel->brands()->pluck('id'))) ) - ->get(); + ->when( + auth('backend')->user()->brands()->count() === 1, + fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', auth('backend')->user()->brands()->pluck('id'))) + ); + $claimSubjectModels = $request->filled('brand') || (auth('backend')->user()->brands()->count() === 1) ? + $claimSubjectModels->get() : + null; return view('bo.pages.claims.index', compact('claimModels', 'search', 'searchFields', 'claimSubjectModels')); } diff --git a/resources/views/bo/modules/claim-tools.blade.php b/resources/views/bo/modules/claim-tools.blade.php index 4c4edfd..db6a04f 100644 --- a/resources/views/bo/modules/claim-tools.blade.php +++ b/resources/views/bo/modules/claim-tools.blade.php @@ -9,20 +9,22 @@ {{ __('Exporter')}} -
-
- {{-- SUBJECT SELECT --}} - -
-
+ @if (!empty($claimSubjectModels)) +
+
+ {{-- SUBJECT SELECT --}} + +
+
+ @endif {{-- EXPORT MODAL --}}