how to pass data from one view to other view in laravel

I am using laravel to develop my project.
In my controller I have Variable called $products and i’m passing that variable to the view ,

return view('products.index')->with("products",$products);

No any issue till here !

Now i want to pass same $products to the other view,

<a href="{!! route('productsnew.index') !!}"> Click Here </a>

How can i pass $products with this route?

Thanks For the Help !


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

<a href="{{ route('productsnew.index', [ 'products' => $products->pluck('id') ]) }}">some link</a>

Route::get('/some/url/{product_ids}', function($product_ids) {
    Product::whereIn('id', $product_ids)->get();

But you are much better off using a category id.
<a href="{{ route('category.index', [ 'category_id' => $category->id ]) }}">{{ $category->name }}</a>

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x