我想要www.example.com/shop/slug/productname
我有一个错误:
Missing required parameters for [Route: shop.show] [URI:
shop/{slug}/{productName}]. (0)
我为每种产品的路线
{{ route('shop.show',[$product->slug,$product->name]) }}
是我的ShopController
public function show($slug,$productName)
{
$productslug = Product::where('slug',$slug)->firstOrFail();
$productname = Product::where('name',$productName)->firstOrFail();
$mightAlsoLike = Product::where('slug', '!=' ,$slug)-
>MightAlsoLike()->get();
return view('front.product')
->with('product', $productname)
->with('product', $productslug)
->with( 'mightAlsoLike', $mightAlsoLike);
}
是我的web.php:
Route::get('/shop/{slug}/{productName}', 'ShopController@show')->name('shop.show');
您必须在多个路由参数的情况下传递密钥。
Route::get('/shop/{slug}/{productName}', 'ShopController@show')->name('shop.show');
并使用这样的路线:
{{ route('shop.show',['slug'=>$product->slug,'productName'=>$product->name]) }}