You don't have $id
argument on your function, if you want to list all products, use this:
function ShowProducts() {
$products = ProductModel::all();
return view('profile', ['products' => $products]);
}
and on your blade:
@foreach($products as $prod)
<h3 class="product-title">
<a href="product.html">{{$prod->Product_Name}}</a>
</h3>
@endforeach
If you want to show a single product, add a new route with {id}
:
Route::get('/ShowProducts/{id}' , 'ProductController@ShowProduct');
and on your controller:
function ShowProduct($id) {
$product = ProductModel::findOrFail($id);
return view('profile', ['product' => $product]);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…