Я использую пакет Gloudemans Shopping Cart и пытаюсь получить "отдельные элементы корзины из столбца cart " в базе данных, например ' name, price, qty ', но по некоторым причинам, когда я это делаю:
{{ $order['cart]['name'] }}
, я получаю сообщение об ошибке: Недопустимое смещение строки' name '
Но если я это сделаю:
{{ $order['cart'] }}
Я получаю товар целиком: {"027c91341fd5cf4d2579b49c4b6a90da":{"rowId":"027c91341fd5cf4d2579b49c4b6a90da","id":1,"name":"web development","qty":1,"price":70,"weight":1,"options":[],"discount":0,"tax":0,"subtotal":70},"370d08585360f5c568b18d1f2e4ca1df":{"rowId":"370d08585360f5c568b18d1f2e4ca1df","id":2,"name":"graphics","qty":1,"price":100,"weight":1,"options":[],"discount":0,"tax":0,"subtotal":100}}
Пожалуйста, как мне решить эту проблему?
Вот мои файлы:
CheckoutController. php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\AccountOrder;
use Cart;
class CheckoutController extends Controller
{
public function myOrder($id)
{
$orders = auth()->user()->orders;
return view('frontend/academic/myOrder')
->with('orders', $orders);
}
}
ShoppingController. php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Category;
use App\AccountOrder;
use Cart;
class ShoppingController extends Controller
{
//function to add course to cart
public function add_to_cart(Request $request, $pid)
{
$product = Category::findOrFail($pid);
// insert into cart
$cart = Cart::add([
'id' => $product->id,
'name' => $product->name,
'price' => $product->price,
'qty' => 1,
'weight' => 1,
]);
if(route('cart.success', $pid))
{
if($request->status === 'successful')
{
$data = auth()->user()->orders()->create([
'cart' => Cart::content(),
'transaction_id' => $request->transaction_id,
'status' => $request->status
]);
//Cart::destroy();
dd($data);
return view('frontend/academic/success');
}
}
return redirect('cart');
}
}
myOrder . лезвие. php
@extends('layouts.front');
@section('content')
<div class="container-fluid">
<div class="row medium-padding120 bg-border-color">
<div class="container">
<div class="order">
<h2 class="h1 order-title text-center">My Order</h2>
@foreach ($orders as $order)
<div class="card mb-5">
<div class="card-header bg-info">
Purchased Date: {{$order->created_at->toFormattedDateString()}}
</div>
<div class="card-body">
<ul class="list list-group">
<li class="list-group-item">
//Here is my Problem
{{$order['cart']['name']}} {{$order['cart']['price']}}
<span class="badge"></span>
</li>
</ul>
</div>
<div class="card-footer bg-info">
<?php $variable = $order->cart ?>
//Here is also my Problem
<strong>Total Price: {{ $order['cart']['subtotal'] }} </strong>
</div>
</div>
@endforeach
</div>
</div>
</div>
</div>
@endsection