當(dāng)我在 Laravel 中創(chuàng)建“添加到購(gòu)物車”頁(yè)面時(shí),出現(xiàn)錯(cuò)誤,ExceptionProperty [prod_name] does not exist in this collection instance. (View: C:\xampp\htdocs\bizzcomputer\resources\views\cart.blade.php)這是我的購(gòu)物車控制器<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use App\Product;use App\Category;class CartController extends Controller{ public function index() { $products = Product::get(); return view ('cart')->with(compact('products')); } public function create() { // } public function store(Request $request) { // } public function show($id) { $product = Product::find($id); return view('cart')->with(compact('product')); } public function edit($id) { // } public function update(Request $request, $id) { // } public function destroy($id) { // }}這是我的產(chǎn)品頁(yè)面 href 到購(gòu)物車頁(yè)面。單擊添加到購(gòu)物車時(shí),它會(huì)定向到購(gòu)物車頁(yè)面。 <div class="ml-md-3"> <a href="{{route('cart',$product->id)}}" class="btn px-5 btn-primary-dark transition-3d-hover"><i class="ec ec-add-to-cart mr-2 font-size-20"></i> Add to Cart</a> </div>這是我的路線。web.phpRoute::get('/cart/{id}', 'CartController@show')->name('cart');Route::get('/cart', 'CartController@index')->name('cart');可能是什么問(wèn)題?有人請(qǐng)指導(dǎo)我找出這個(gè)嗎?
1 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
該系列中有很多產(chǎn)品$products,您需要循環(huán)播放才能獲得prod_name
@foreach($products as $product)
<td data-title="Product">
<a href="#" class="text-gray-90">{{ $product->prod_name }}</a>
</td>
@endforeach
- 1 回答
- 0 關(guān)注
- 101 瀏覽
添加回答
舉報(bào)
0/150
提交
取消