I have a controller que find the products and return to view . Current I'm trying make the pagination and I'm using the following code :
return $this->queryProductsAvailable()
->where('fornecedores.plano_id', $plano)
->select('produtos.*')
->paginate( $limit );
function queryProductsAvailabe:
private function queryProductsAvailable()
{
return Products::join('fornecedores', 'fornecedores.id', '=' ,'produtos.fornecedor_id')
->where( 'fornecedores.ativo', '1')
->where( 'produtos.moderacao', 'P' )
->where( 'produtos.ativo' , '1' )
->where( 'produtos.preco_min', '>', 0 )
->select( 'produtos.*');
}
To view I'm return the following:
return view('Catalogo.index',
[
'products' => $products
]
);
But when I run the method $products->render()
nothing happens.
No errors, no messages...
if I run $products->total()
is returned the value 0
if I run $products->nextPageUrl()
nothing happens
The same variable used to access this methods is used for the loop and print of products and the foreach works fine.
if I access the url with /?page=2
the pagination works, but not render list of pages.
Any idea?
---- Edite ----
The code works as follows:
In my site there are plans (plans 5 levels) that will make the products are listed before the other, then the search for the product I do the following:
In the first search I seek 30 level products 5 if the level 5 does not have 30 products I check how many products brought to query, I reduce the 30 and seek more product in the plan 4 to complete the 30 products and so on.
In this process, when we decrease a plan I use the push methodo to add the collection and whenever there is the decrease in the plan, the paginate limit is also being changed ...
So I have two points that may be causing this problem, the first is the push method and the second in the act of reducing the plan and seek more products with a different paginate the first one was 30.
Other than that my query also search products randomly, I believe that I need to develop my own paginate to meet all my requirements ...
Thank you all
render()
won't do anything if you have less than the number of results you are paginating. – user1669496