I’m working on a Laravel project where I have two collections of jobs: one paginated and one static. Here’s the code in my controller:
<code>$jobs = Job::with('employer', 'tags')
->latest()
->paginate(10);
$futuredJobs = Job::with('employer', 'tags')
->latest()
->where('featured', 1)->orderByDesc('id')->take(3)->get();
$tags = Tag::all();
return view('job.index', ['jobs' => $jobs, 'tags' => $tags, 'futuredJobs' => $futuredJobs]);
</code>
<code>$jobs = Job::with('employer', 'tags')
->latest()
->paginate(10);
$futuredJobs = Job::with('employer', 'tags')
->latest()
->where('featured', 1)->orderByDesc('id')->take(3)->get();
$tags = Tag::all();
return view('job.index', ['jobs' => $jobs, 'tags' => $tags, 'futuredJobs' => $futuredJobs]);
</code>
$jobs = Job::with('employer', 'tags')
->latest()
->paginate(10);
$futuredJobs = Job::with('employer', 'tags')
->latest()
->where('featured', 1)->orderByDesc('id')->take(3)->get();
$tags = Tag::all();
return view('job.index', ['jobs' => $jobs, 'tags' => $tags, 'futuredJobs' => $futuredJobs]);
In my Blade template, I use the paginator to display the paginated jobs:
<code>@foreach ($jobs as $job)
<!-- Display job details -->
@endforeach
{{ $jobs->links() }}
@foreach ($futuredJobs as $featuredJob)
<!-- Display featured job details -->
@endforeach
</code>
<code>@foreach ($jobs as $job)
<!-- Display job details -->
@endforeach
{{ $jobs->links() }}
@foreach ($futuredJobs as $featuredJob)
<!-- Display featured job details -->
@endforeach
</code>
@foreach ($jobs as $job)
<!-- Display job details -->
@endforeach
{{ $jobs->links() }}
@foreach ($futuredJobs as $featuredJob)
<!-- Display featured job details -->
@endforeach
New contributor
Ahamed Rasni Nathees is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.