我想在用户定义的表中将数据库存储在数据库中。 但是当我调用save();在控制器中的方法,它给我错误!
这是我的控制器的功能
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();
}
答案 0 :(得分:1)
最可能的问题是你有两个冲突的do
{
// Literally do nothing while the condition is true.
}
while (!HttpContext.Current.User.IsAuthenticated);
类名,一个很可能是包,另一个是你的模型。
您可以通过以下方式解决此问题:
如下所示包含您的模型:
Cart
将此更改为:
use models\Cart;
答案 1 :(得分:0)
希望您按照here给出的步骤进行操作。检查您的config/app.php
>下线的提供者数组:
Gloudemans\Shoppingcart\ShoppingcartServiceProvider::class
如果不存在则将其放置并检查。可能是这个例外的原因。
答案 2 :(得分:0)
使用package shoppingcart表来克服凌乱的外观,以良好的方式检索数据,您可以在控制器中捕获shoppingcart表,如:
public function dbcart(){
$cc=DB::table('shoppingcart')
->get();
return view('dbcart',compact('cc'));
}
然后在你的视图中dbcart.blade.php首先反序列化内容,然后迭代它:
@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