Laravel 4: How to make pagination
10,056
In your controller
public function show(){
$photos = Photo::paginate(10);
return View::make('photos.show', array('photos' => $photos));
}
and then in your view just do this
@foreach ($photos as $photo)
{{ $photo->title }}
@endforeach
// executed from passed variable into view
{{ $photos->links() }}
![FrancescoMussi](https://i.stack.imgur.com/fTYHK.jpg?s=256&g=1)
Author by
FrancescoMussi
Full-stack developer based in Riga, Latvia. Hope Socrates is proud of my Socratic badge on StackOverflow.
Updated on June 04, 2022Comments
-
FrancescoMussi about 2 years
Right now i have a working photo-gallery with basic Crud. In the view Show, under the picture, i would like to add the pagination: giving the possibility to watch other pictures remaining in the Show view, instead of coming back to the Index view.
I try to read the documentation: http://four.laravel.com/docs/pagination But is not working.
Can someone please tell me what exactly i have to do?
Thank you very much!
EDIT:
This is the Show method:
public function show($id) { $photo = Photo::find($id); return View::make('photos.show', compact('photo')); }
And this is the Show view:
@extends('master') @section('blog') <div class="span12 well"> <div class="span12"> <h4> {{ $photo->title }} </h4> <p>{{ $photo->caption }} </p> </div> </div> <div class="span12 well"> <figure> <img src="../{{ $photo->path }}" alt="{{ $photo->caption }}"> <br><br> <div class="span2"> {{ link_to_route('photos.index', '« Back to Index') }} </div> </figure> </div> @stop