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 ?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With