Php 将会话数据从控制器传递到视图laravel不能将stdClass类型的对象用作数组
我的代码有错误。我正在将数据从控制器传递到视图。我试图打印数据,这样我就可以看到数据的结构 这是我的控制器:Php 将会话数据从控制器传递到视图laravel不能将stdClass类型的对象用作数组,php,arrays,session,object,laravel-5.4,Php,Arrays,Session,Object,Laravel 5.4,我的代码有错误。我正在将数据从控制器传递到视图。我试图打印数据,这样我就可以看到数据的结构 这是我的控制器: public function getAllCart() { if (!Session::has('cart')) { return view('mycartview'); } $oldCart = Session::get('cart'); $cart = new Cart($oldCart); print_r($cart);
public function getAllCart()
{
if (!Session::has('cart')) {
return view('mycartview');
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);
print_r($cart);
return view('mycartview', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice]);
}
我的看法是:
@foreach($products as $product)
<li class="list-group-item">
<span class="badge"></span>
<strong>{{ $product['item']['title'] }}</strong>
<span class="label label-success">{{ $product['price'] }}</span>
<button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown">Action <span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Reduce by 1</a></li>
<li><a href="#">Remove all</a></li>
</ul>
</li>
@endforeach
对象
项中没有标题
,如果有的话,您可以像{{$product['item']->title}}
lol wow感谢它是$product['item']->标题一样访问它。我忘了传递标题,但是$product['item']->title谢谢,很高兴能帮上忙对象item
中没有title
,如果有的话,你也许可以像{$product['item']->title}}
哈哈,谢谢这是$product['item']->title}一样访问它。我忘了传递标题,但它可以$product['item']->title thanksnp,很高兴为您提供帮助
App\Cart Object ( [items] => Array ( [2] => Array ( [qty] => 2 [price] => 30000 [item] => stdClass Object ( [product_id] => 2 [subcategory_id] => 2 [price] => 15000 [quantity] => 5 [status] => published [created_at] => 2017-08-23 05:41:02 [updated_at] => 2017-08-23 05:41:02 ) ) ) [totalQty] => 1 [totalPrice] => 15000 )