1
votes

I have two methods:

public function specific_shop(Request $request)
{
    $categories = Category::all();
    $products = Product::where('shop_id', $request->id)->orderBy('quantity', 'asc')->paginate(10);
    return view('product.show', compact('products', 'categories'));

}
public function specific_category(Request $request)
{
    $products = Product::where('category_id', $request->id)->orderBy('quantity', 'asc')->paginate(10);
    return view('product.specific', compact('products'));
}

The first one is giving me Products from specific shop (after choosing from select input) and the second one is giving me Products from specific category.

Route::resource('product', 'ProductController');
Route::get('/product/show/shop/specific', 'ProductController@specific_shop');
Route::get('/product/show/category/specific', 'ProductController@specific_category');

Pagination works when I hit /product/ and it shows all products (not specified) but if I hit /product/show/shop/specific (via form) pagination is not working correctly. It seems like it doesn't even work at all. First page is fine but if I click next, it returns nothing. Blank table. I don't know why.

1

1 Answers

1
votes

Do this

 $id = $request->id;
return view('product.specific', compact('products','id'));

Then in your view instead of

{{ $products->links() }}

Do this

{{ $products->appends(['id' => $id])->links() }}

Issue : the id field is not being passed to the second page i guess.

Also it's better to put the ressource route at the bottom to avoid any trouble

Route::get('/product/show/shop/specific', 'ProductController@specific_shop');
Route::get('/product/show/category/specific', 'ProductController@specific_category');
Route::resource('product', 'ProductController');