使用cookie在laravel中存储和检索订单数据

时间:2018-06-24 11:39:29

标签: laravel laravel-5 cookies

使用cookie在laravel中存储和检索订单数据

我想使用cookie来存储和检索商店订单中的订单数据:

$('select').change(function () {
  if ($('select option:selected').text() === 'First Option Text') {
    
    console.log( $('select option:selected').attr('value'));
  }
  else if ($('select option:selected').text() === 'Second Option Text') {
    
    console.log( $('select option:selected').attr('value'));
  }
  else if ($('select option:selected').text() === 'Thrid Option Text') {
   
    console.log( $('select option:selected').attr('value'));
  }
});

检索订单数据以进行付款操作:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select>
  <option value=1 id="firstOption">First Option Text</option>
  <option value=2 id="secondOption">Second Option Text</option>
  <option value=2 selected id="thirdOption">Thrid Option Text</option>
</select>

但发生此错误

SQLSTATE [23000]:违反完整性约束:1048列“ order_id”不能为空

怎么了

1 个答案:

答案 0 :(得分:0)

嗨,您可以尝试Cookie :: get();检索Cookie

 public function storeReceipt(Request $request, $method) {

            $request->validate([
                'price' => 'required|numeric',
            ]);

            $request['order_id'] = Cookie::get('orderId');
            $request['method'] = $method;


            $created = Payment::create($request->all());

            return $created->count() > 0
                ? redirect()->route('home')->with('alert', 'success')
                : redirect()->route('payment/method/create', 'receipt')->with('alert', 'error');
        }