2

首先我必须告诉你我的代码在我的本地主机上工作,我得到的错误只在部署后的开发服务器上。

我收到错误$list = Listing::create($data);

这是我的 $data 有效载荷

array:25 [
  "seller1_name" => "Seller 1"
  "seller2_name" => "Seller 2 test"
  "listing_date" => "2020-12-17"
  "listing_expire_date" => "2020-12-29"
  "address" => "New addrs"
  "city" => "new city"
  "state" => "new state"
  "zip" => "1231231"
  "list_price" => "4343434"
  "step_template_id" => 8
  "broker_fee_type" => "$"
  "transaction_fee" => "342342342342"
  "cobroker_split_type" => "$"
  "school_district" => "dsadasad"
  "broker_fee" => "3424234"
  "cobroker_split" => "34243"
  "agents" => array:2 [
    0 => array:2 [
      "key" => 78
      "value" => "Agent1 user"
    ]
    1 => array:2 [
      "key" => 84
      "value" => "Agent2 user"
    ]
  ]
  "admin_id" => 68
  "login_user_id" => 68
  "login_email" => "webkeeda@yopmail.com"
  "chargebee_plan_id" => "starter"
  "customer_id" => "AzZlzTSI5w7bDEMt"
  "role_id" => 1
  "user_company" => null
  "created_by" => 68
]

我的 Listing.php 模型有多对多的关系

public function agents()
    {
        return $this->belongsToMany('App\User', 'listing_agents', 'listing_id', 'agent_id');
    }

如果您需要我的任何其他信息,请在评论中告诉我。

编辑:

为了在我的关系中存储数据,我正在使用它。

$agents = $request->agents;
            array_walk($agents, function (& $item, $key, $listing) {
                $item['listing_id'] = $listing->id;
                $item['agent_id'] = $item['key'];
                unset($item['key']);
            }, $listing);

            if($listing) {
                $listing->listing_agents()->createMany($agents);
            }

关系:

public function listing_agents()
    {
        return $this->hasMany('App\ListingAgent', 'listing_id');
    }
4

0 回答 0