我在尝试使用slug获取页面产品详细信息时出错它已经存储在我的数据库中
在此处输入图像描述
不,这是我的index.blade.php 中的代码
<div class="ps-shoe__thumbnail"><a class="ps-shoe__favorite" href="#"><i class="ps-icon-heart"></i></a><img src="{{ $product->image }}" alt=""><a class="ps-shoe__overlay" href="{{ route('products.show', $products->slug) }}"></a>
这是路线
Route::get('/all/{slug}', 'ProductsController@show')->name('products.show');
这是我的控制器中的显示功能
public function show($slug){
$products = products::where('slug', $slug)->first();
return view('products.show')->with('products', $products);
}
提前感谢
您将$products
传递给刀片,但将其用作$product->image
。我认为这是你的问题。
<div class="ps-shoe__thumbnail"><a class="ps-shoe__favorite" href="#"><i class="ps-icon-heart"></i></a><img src="{{ $products->image }}" alt=""><a class="ps-shoe__overlay" href="{{ route('products.show', $products->slug) }}"></a>
我在这里看到的问题:
替换自:
public function show($slug){
$products = products::where('slug', $slug)->first();
return view('products.show')->with('products', $products);
}
替换为:
public function show($slug){
$products = Product::where('slug', $slug)->first();
return view('products.show')->with('products', $products);
}
请确保您在产品中使用了大写字母"p",并删除了最后一个"S",因为我们需要使用复数形式的模型。我还认为,正因为如此,你无法从数据库中获取数据。