I’ve got an admin-type page that allows the use to either
There are some basic limitations in this, as you cannot search for more than 50 courses. I don’t want to get into a pagination by query result issue here, as that requires screwing around with the pagination more than I’d like to.
What I’d like to do is simply work out in the view whether or not to use:
{{ $courses->links() }}
At the moment, if I make a search, it doesn’t use pagination, so of course I get:
Method Illuminate\Database\Eloquent\Collection::links does not exist
Here’s my method:
public function index(Request $request)
{
$query = $request->query('q');
$courses = Course::orderBy('name');
if ($query) {
$courses = $courses->where('name', $query)->limit(50);
} else {
$courses = $courses->paginate(50);
}
return view('courses.index')
->with('q', $query)
->with('courses', $courses);
}
Try this
{{isset($courses->links()) ? $courses->links() : null }}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community