Reputation: 117
I want to store a cart in database in user defined table. But when I call save(); method in controller, It gives me error like!
Here is the function of my controller
public function store(Request $request){
$this->validate($request, [
'guest_name' => 'required|max:255',
'guest_phone' => 'required',
'guest_email' => 'required',
'guest_address' => 'required',
]);
$guest = new Guest;
$guest->name = $request->guest_name;
$guest->phone = $request->guest_phone;
$guest->email = $request->guest_email;
$guest->address = $request->guest_address;
$guest->payment_method = $request->payment_method;
$guest->save();
$cart = new Cart;
$cartDetails = Cart::content();
$subtotal = Cart::subtotal();
foreach($cartDetails as $c){
$cart->guest_id = $guest->id;
$cart->products = $c->name;
$cart->qty = $c->qty;
$cart->price = $c->price;
$cart->subtotal = $c->subtotal;
$cart->save();
}
return view('guest/track')->with('msg','Your Order has been placed! You\'ll get an email shortly!');
//$find = DB::table('guests')->where('id',$guest->id)->first();
}
Upvotes: 0
Views: 1725
Reputation: 1
using the package shoppingcart table, to overcome the messy look, to retrieve data in a good manner you can catch shoppingcart table in your controller like:
public function dbcart(){
$cc=DB::table('shoppingcart')
->get();
return view('dbcart',compact('cc'));
}
and then in your view dbcart.blade.php first unserialize the content and then iterate over it:
@extends('cmaster')
@section('content')
@foreach($cc as $item)
<?php $pp=unserialize($item->content) ?>
@foreach ($pp as $it)
{{$it->name}}<br/>
{{$it->qty}}<br/>
@endforeach
@endforeach
@endsection
Upvotes: 0
Reputation: 21681
Hope you followed the steps given at here. Check your config/app.php
> providers array for below line:
Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class
If it not there then place it and check. May be this is the reason for this exception.
Upvotes: 0
Reputation: 768
The most probable problem is you have 2 conflicting class names of Cart
, one is most probably the package and the other being your model.
You can get around this by the following:
When including your model like the following:
use models\Cart;
Change this to something like:
use models\Cart as CartModel;
Upvotes: 1