尝试使用axios在laravel上获取非对象的属性

时间:2018-10-31 17:16:30

标签: php laravel laravel-5 vue.js axios

我在这里有一个小问题,希望得到您的帮助。

axios.get('/api/NewOrder',{params: {shippingInfo: this.Costumer,shipping_date: this.shipping_date,orderIteams:this.orderIteams,payments:this.payments,ordertotal:this.ordertotal,totalrecieved:this.totalrecieved}}).then(response => {
    alert(response.data);
    });

当使用axios调用api时出现此错误 “ message”:“试图获取非对象的属性”, 这是我的功能:

    public function store(Request $request)
{
  $neworder=new Order;
  $neworder->operatorId=auth()->guard('admin-web')->user()->id;
  $neworder->outletId= auth()->guard('admin-web')->user()->outletid;
  $neworder->shippingInfo=$request->query('shippingInfo');
  $neworder->shipping_date=$request->query('shipping_date');
  $neworder->status="en attente";
  $neworder->order_total=$request->query('ordertotal');
  $totalrecieved=$request->query('totalrecieved');
  if ($totalrecieved < $neworder->order_total) {
    $neworder->paymentStatus="payement partial";
  }else {
    $neworder->paymentStatus="payee";
  }
  $neworder->save();
  $neworder->number = date("Y").$neworder->outletId.$neworder->operatorId.$neworder->id;
  $neworder->save();


  return response()->json($neworder->number);
}

预先感谢

2 个答案:

答案 0 :(得分:0)

因此我认为

$totalrecieved=$request->query('$totalrecieved');

$totalrecieved=$request->query('totalrecieved');

答案 1 :(得分:0)

已解决 问题只是调用了auth()而没有定义它