@php // Check if data is passed from controller (paginated) or need to fetch (included view) if (!isset($jobs)) { $headofficeid = $user->selected_head_office->id; $search = request()->get('search', ''); $filter = request()->get('filter', 'all'); $query = App\Models\UserJob::with([ 'subtypes' => function($q) use ($headofficeid) { $q->where(function($query) use ($headofficeid) { $query->where('headoffice_id', $headofficeid)->orWhereNull('headoffice_id'); }); }, 'head_office_job' => function($q) use ($headofficeid) { $q->where('head_office_id', $headofficeid); } ]) ->where(function($q) use ($headofficeid) { $q->where('headoffice_id', $headofficeid)->orWhereNull('headoffice_id'); }); if ($search) { $query->where('job', 'LIKE', "%{$search}%"); } if ($filter === 'custom') { $query->where('headoffice_id', $headofficeid); } elseif ($filter === 'activated') { $query->whereHas('head_office_job', function($q) use ($headofficeid) { $q->where('head_office_id', $headofficeid)->where('status', 0); }); } elseif ($filter === 'deactivated') { $query->whereHas('head_office_job', function($q) use ($headofficeid) { $q->where('head_office_id', $headofficeid)->where('status', 1); }); } $jobs = $query->paginate(100); $jobIds = $jobs->pluck('id')->toArray(); $overrides = App\Models\UserTypeOverrides::where('head_office_id', $headofficeid) ->whereIn('user_type_id', $jobIds) ->pluck('job_description', 'user_type_id')->toArray(); $subtypeSelections = App\Models\SubtypeSelection::where('head_office_id', $headofficeid) ->whereIn('user_type_id', $jobIds) ->pluck('can_select_multiple', 'user_type_id')->toArray(); $createCategories = App\Models\UserTypeCategories::where('head_office_id', $headofficeid)->get(); } else { $headofficeid = $headofficeid ?? $user->selected_head_office->id; } $categories = $createCategories ?? App\Models\UserTypeCategories::where('head_office_id', $headofficeid)->get(); $search = $search ?? ''; $filter = $filter ?? 'all'; @endphp
{{-- --}} @foreach ($jobs as $job) @php // Use eager loaded data $headofficeJob = $job->head_office_job; $Isactivated = $headofficeJob && $headofficeJob->status == 1; $jobDescription = $overrides[$job->id] ?? $job->job_description; $canSelectMultiple = $subtypeSelections[$job->id] ?? 0; @endphp @endforeach
Category User Type DescriptionExampleSubtype Action
@livewire('user-type-cat', ['jobId' => $job->id])
{{ $job->job }}
Also Ask if

@foreach ($job->subtypes as $subtype) {{ $subtype->subtype_name }} @endforeach
@if ($Isactivated) @else @endif @if ($job->headoffice_id == $headofficeid) @endif
{{--
--}}
Showing {{ $jobs->firstItem() ?? 0 }} to {{ $jobs->lastItem() ?? 0 }} of {{ $jobs->total() }} user types
{{ $jobs->appends(['search' => $search, 'filter' => $filter])->links('pagination::bootstrap-4') }}