laravel - 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>
推荐阅读
- xml - 将巨型 XML 文件拆分为 n 个子版本
- github - 如何使用 GitHub GraphQL API 在项目中的列之间移动问题?
- spring - EntityManagerHolder 不能转换为 org.springframework.orm.hibernate5.SessionHolder
- node.js - Firestore 响应拦截器
- ios - UIScreen.main 、 super.view 和其他视图的中心不在屏幕中间
- kentico - 在 Kentico 中——如何在网页上显示表单中的数据?
- windows - influxdb.conf 文件中不存在 Influxdb [admin] 部分
- sql - postgresql 在时间序列中选择布尔状态
- sparql - 来自 dbpedia.org 的正确语法 SPARQL 查询
- java - Apache POI:Excel 更改了我的格式字符串