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:
$jobs = Job::with('employer', 'tags')
->latest()
->paginate(10);
$futuredJobs = Job::with('employer', 'tags')
->latest()
->where('featured', 1)->latest()
->paginate(6);
$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:
@foreach ($jobs as $job)
<!-- Display job details -->
@endforeach
{{ $jobs->links() }}
@foreach ($futuredJobs as $featuredJob)
<!-- Display featured job details -->
@endforeach
2
Answers
Wat means static and non static? U have 2 similar collections, just different data. Also u have doubled latest() in second one
Not sure what your problem is but from what I understand use
get()
instead ofpaginate(6)
in$futureJobs
.If you want to show only latest 6 jobs use
Note that
Also there are 2
latest()
in$futureJobs
only use one.Also
compact('jobs','tags','futuredJobs')
instead of['jobs' => $jobs, 'tags' => $tags, 'futuredJobs' => $futuredJobs]
can be used while returning variables to view.