@if(isset($jobs) && ($jobs instanceof \Illuminate\Contracts\Pagination\Paginator || $jobs instanceof \Illuminate\Contracts\Pagination\LengthAwarePaginator))
Showing {{ $jobs->firstItem() }}-{{ $jobs->lastItem() }} of {{ $jobs->total() }} jobs
@elseif(isset($jobs) && is_countable($jobs))
Showing 1-{{ count($jobs) }} of {{ count($jobs) }} jobs
@else
Showing jobs
@endif
@php
if (!isset($jobs)) {
try {
$query = \App\Models\Job::query()->where('is_active', true);
$categoryFilter = request('category');
if (!empty($categoryFilter)) {
// Try resolve category by slug or name
$categoryModel = \App\Models\Category::where('slug', $categoryFilter)
->orWhere('name', $categoryFilter)
->first();
$query->where(function ($q) use ($categoryModel, $categoryFilter) {
// 1) Pivot relation when available
if ($categoryModel) {
$q->whereHas('jobCategories', function ($qq) use ($categoryModel) {
$qq->where('job_categories.id', $categoryModel->id);
});
}
// 2) JSON categories fallback with common casing variants
$candidates = [];
if ($categoryModel) {
$name = (string) $categoryModel->name;
$slug = (string) $categoryModel->slug;
$candidates = [
$name,
$slug,
strtolower($name),
strtoupper($name),
ucwords(strtolower($name)),
str_replace(['-', '_'], ' ', $slug),
];
} else {
$val = (string) $categoryFilter;
$candidates = [
$val,
strtolower($val),
strtoupper($val),
ucwords(strtolower($val)),
str_replace(['-', '_'], ' ', $val),
];
}
foreach (array_unique($candidates) as $cand) {
if ($cand !== '') {
$q->orWhereJsonContains('categories', $cand);
}
}
});
}
$jobs = $query->latest()->paginate(5)->withQueryString();
} catch (\Throwable $e) {
$jobs = collect();
}
}
$siteCompany = \App\Models\Company::first();
@endphp
@forelse($jobs as $job)
- {{ optional($job->company)->name ?? ($siteCompany->name ?? 'Company') }}
- {{ $job->office_location ?? 'Location' }}
- {{ $job->created_at?->diffForHumans() }}
@if(!empty($job->salary_range))
- {{ $job->salary_range }}
@endif
- {{ $job->job_type ?? 'Full Time' }}
@if(!empty($job->work_location))
- {{ $job->work_location }}
@endif
@empty
@endforelse
@if($jobs instanceof \Illuminate\Contracts\Pagination\Paginator || $jobs instanceof \Illuminate\Contracts\Pagination\LengthAwarePaginator)
@endif