I am working on adding the product values into the cart and i am using darryldecode Laravel shopping cart. When I try to get the image and total price from the attribute array, I get the error Undefined property: stdClass::$total
.
Here is my Controller:
public function cart(Request $request , $id)
{
// return $request;
$cart = Cart::add([
'id' => $request->id,
"name" => $request->name,
"crm" => $request->sku,
"quantity" => $request->qty,
"price" => $request->price,
"attributes" => array(["image" => $request->image] , "total" => $request->price * $request->qty)
]);
if($cart)
{
return redirect()->route('cart');
}
}
Here is the Cart Controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Cart;
class CartController extends Controller
{
public function index()
{
// return Cart::getContent();
return View('demo', [ 'cart' => Cart::getContent()]);
}
}
Here is the view where I try to print the image and total
@foreach($cart as $product)
Name:<td></td>
Price:<td></td>
Quantity:<td></td>
Attributes:<td></td>
@foreach(json_decode($product->attributes) as $details)
Image:<td></td>
Total:<td></td>
@endforeach
@endforeach
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2sYWcah
via IFTTT
Aucun commentaire:
Enregistrer un commentaire