Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if used paginate in laravel

Tags:

I have a custom view and in some functions, I used paginate and other functions I don't use paginate. now how can I check if I used paginate or not ?

@if($products->links())

   {{$products->links()}}

@endif // not work 

of course that I know I can use a variable as true false to will check it, But is there any native function to check it ?

like image 315
S.M_Emamian Avatar asked Oct 11 '16 12:10

S.M_Emamian


People also ask

How can I get pagination in Laravel?

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 provided by Laravel automatically takes care of setting the proper limit and offset based on the current page being viewed by the user.

How does Laravel pagination work?

Pagination works by selecting a specific chunk of results from the database to display to the user. The total number of results is calculated and then split between pages depending on how many results you want to return on a page.

How can I use pagination in Laravel 8?

To perform pagination in laravel, you just have to use the paginate () function instead of all () or get() functions as used in maximum time. Paginate method takes a number as a parameter. It defines how much data you want to show on one page or section.


1 Answers

This works perfectly. Check if $products is an instance of Illuminate\Pagination\LengthAwarePaginator then display the pagination links.

@if($products instanceof \Illuminate\Pagination\LengthAwarePaginator )

   {{$products->links()}}

@endif
like image 69
Richie Avatar answered Sep 21 '22 00:09

Richie