In my Laravel (5.7) controller, I have set pagination + 'on each side navigation' to 2 items. However, this is not working on my view. I'm getting much more items than 2, which causes my window to break out on small mobile devices.
What can be the cause of this and how can I fix it? I mean, I can get it fixed with CSS, but I would like to get it fixed the proper way.
My code in the controller:
public function index(Request $request)
{
$type = 'all';
if ($request->has('type')) {
if ($request->type == 'all') {
$materials = Material::paginate(10)->onEachSide(2);
} else {
$type = $request->type;
$materials = Material::where('type', $type)->paginate(10)->onEachSide(2);
}
} else {
$materials = Material::paginate(10)->onEachSide(2);
}
$stock = array(
'enkelzitKajaks' => Material::where('type', 'Enkelzitkajak')->count(),
'dubbelzitKajaks' => Material::where('type', 'Dubbelzitkajak')->count(),
'canadeseKanos' => Material::where('type', 'Canadese kano')->count(),
'langePeddels' => Material::where('type', 'Lange peddel')->count(),
'kortePeddels' => Material::where('type', 'Korte peddel')->count(),
'tonnetjes' => Material::where('type', 'Tonnetje')->count(),
'zwemvesten' => Material::where('type', 'Zwemvest')->count()
);
return view('materials.index')->with('materials', $materials)->with('stock', $stock)->with('type', $type);
}
My code in the view:
<section class="pagination">
<div class="container">
<div class="row">
<div class="col-12">
{{ $materials->links() }}
</div>
</div>
<hr>
</div>
</section>
A screenshot of my view on small devices:
