“未定义的属性:stdClass :: $ order”

时间:2019-02-16 16:23:34

标签: php laravel

当我想打开“订单状态”页面时,出现此错误:

  

“未定义的属性:stdClass :: $ order    $ order-> update(['order_no'=> $ item-> order]);

页面控制器:

public function cron(){
    $orders = Order::where('status', 'Pending')->where('service_no', '!=', 0)->get();
    $api = ApiSetting::first();
    foreach ($orders as $order){
        if($this->orderExists($order->order_no)){
            continue;
        }else {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $api->url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,
                "api_token=".$api->key."&action=add&package=".$order->service_no."&link=".$order->link."&quantity=".$order->quantity);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $server_output = curl_exec ($ch);
            $item = json_decode($server_output);
            $order->update(['order_no'=> $item->order]);
            curl_close ($ch);
        }
    }
}

订购型号代码:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $guarded = [];
  public function category(){
      return $this->belongsTo(Category::class, 'category_id', 'id');
  }

    public function service(){
        return $this->belongsTo(Service::class, 'service_id', 'id');
    }

    public function user(){
        return $this->belongsTo(User::class, 'user_id', 'id');
    }
}

0 个答案:

没有答案