php - how to display 36 images per page using thumbnail bootstrap3?
one text
Solution:
There are several ways to paginate items. The simplest is by using the paginate
method on the query builder or an Eloquent query. The paginate
method automatically takes care of setting the proper limit and offset based on the current page being viewed by the user. By default, the current page
is detected by the value of the page query string argument on the HTTP request. This value is automatically detected by Laravel, and is also automatically inserted into links generated by the paginator.
In this example, the only argument passed to the paginate
method is the number of items you would like displayed "per page". In this case, let's specify that we would like to display 36
items per page:
public function index()
{
$annonces = Annonce::paginate(36);
return view('annonces.index')->with([
'annonces' => $annonces,
]);
}
Displaying Pagination Results
When calling the paginate
method, you will receive an instance of Illuminate\Pagination\LengthAwarePaginator
. When calling the simplePaginate
method, you will receive an instance of Illuminate\Pagination\Paginator
. These objects provide several methods that describe the result set. In addition to these helpers methods, the paginator instances are iterators and may be looped as an array. So, once you have retrieved the results, you may display the results and render the page links using Blade:
<div class="container">
@foreach ($annonces as $annonce)
{{ $annonce->titre }}
@endforeach
</div>
{{ $annonces->links() }}
The links method will render the links
to the rest of the pages in the result set. Each of these links will already contain the proper page
query string variable. Remember, the HTML generated by the links
method is compatible with the Bootstrap CSS framework.