laravel 如何将数据从一个视图传递到另一个视图

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

我正在使用 laravel 来开发我的项目。 在我的控制器中,我有一个名为 $products 的变量,我正在将该变量传递给视图,

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

到这里没有任何问题!

现在我想将相同的 $products 传递给另一个视图,

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

我怎样才能通过 $products 这个 route

感谢您的帮助!

<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();
})->name('prodictsnew.index');

但是你最好使用类别 ID。

<a href="{{ route('category.index', [ 'category_id' => $category->id ]) }}">{{ $category->name }}</a>