내 PC에 laravel 프로젝트를 개발했습니다. 이 프로젝트를 다른 랩톱으로 복사하고 모두 정상적으로 작동하지만 다음과 같은 오류를주는 단 한 페이지 만 있습니다. 비 객체의 속성을 얻으려고합니다. 이 프로젝트를 개발 한 이상한 일들이 내 PC에 있습니다. 모두 괜찮습니다. 나는 완전히 붙어있다. 이것 좀 도와주세요. 여기 왜 비 객체의 속성을 얻으려고하지만 다른 컴퓨터에서 잘 작동합니까?
실제로 나에게 오류를 제공하는 내 코드입니다 :
CartController : 여기
public function showCart(){
$cart = Cart::where('user_id',Auth::user()->id)->first();
//dd($cart);
if(!$cart){
$cart = new Cart();
$cart->user_id=Auth::user()->id;
$cart->save();
}
$items = $cart->cartItems;
$total=0;
// dd($items);
foreach($items as $item){
$total+=$item->product->price;
}
return view('cart.view',['items'=>$items,'total'=>$total]);
}
내보기 파일입니다 : 여기
@section('content')
<div class="row">
<div class="col-sm-12 col-md-10 col-md-offset-1">
<table class="table table-hover">
<thead>
<tr>
<th>Product</th>
<th></th>
<th class="text-center"></th>
<th class="text-center">Total</th>
<th> </th>
</tr>
</thead>
<tbody>
@foreach($items as $item)
<tr>
<td class="col-sm-8 col-md-6">
<div class="media">
<a class="thumbnail pull-left" href="#"> <img class="media-object" src="{{asset("/images"."/".$item->product->picturePath)}}" style="width: 100px; height: 72px;"> </a>
<div class="media-body">
<h4 class="media-heading"><a href="#">{{$item->product->name}}</a></h4>
</div>
</div></td>
<td class="col-sm-1 col-md-1" style="text-align: center">
</td>
<td class="col-sm-1 col-md-1 text-center"></td>
<td class="col-sm-1 col-md-1 text-center"><strong>{{$item->product->price}}Tk</strong></td>
<td class="col-sm-1 col-md-1">
<a href="/removeItem/{{$item->id}}"> <button type="button" class="btn btn-danger">
<span class="fa fa-remove"></span> Remove
</button>
</a>
</td>
</tr>
@endforeach
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><h3>Total</h3></td>
<td class="text-right"><h3><strong>{{$total}}TK</strong></h3></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>
<a href="/"> <button type="button" class="btn btn-default">
<span class="fa fa-shopping-cart"></span> Continue Shopping
</button>
</a></td>
<form action="{{route('checkout.view')}}" method="post">
{{csrf_field()}}
<input type="hidden" value="{{$total}}" name="total">
<td>
<button type="submit" class="btn btn-success">
Checkout <span class="fa fa-play"></span>
</button></td>
</form>
</tr>
</tbody>
</table>
</div>
</div>@endsection
내 경로 파일이 :
Route::get('/addProduct/{productId}', '[email protected]')-
>name('addcart');
Route::get('/removeItem/{productId}', '[email protected]');
Route::get('/cart', '[email protected]')->name('cart');
경로 :/cart 다른 노트북에서 오류가 발생했지만 (오류 스크린 샷이 아래에 추가됨) 내 PC에서는 정상적으로 작동합니다. 도와주세요. 미리 감사드립니다. enter image description here
줄 62는 무엇입니까? 내 추측 : 그 중 두 번째는 여기에 표시됩니다. 맞습니까? – Jeff
라인 62 :보기 ('cart.view', [ 'items'=> $ items, 'total'=> $ total]); – Nihar