首页 > 解决方案 > laravel如何将数据从一个视图传递到另一个视图

问题描述

我正在使用 laravel 开发我的项目。在我的控制器中$products,我调用了变量并将该变量传递给视图,

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

到这里为止没有任何问题!

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

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

我怎么能通过$products这个route

谢谢您的帮助 !

标签: laravelredirectroutes

解决方案


<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>

推荐阅读