私はテーブルpeoples
countries
とピボットテーブルcountry_people
を持っています。ピボットテーブルの属性はcountries_id
peoples_id
number
です。私はピボットテーブルに外部キーを取得することができますが、私は番号に挿入することはできません。私はこれをどのようにして行うのですか?それはヨーヨーのように見えるピボットテーブルの追加属性にデータを挿入
人々モデル
public function countries()
{
return $this->belongsToMany('App\Country')->withPivot('number')
->withTimestamps();
}
国モデル
public function peoples()
{
return $this->belongsToMany('App\People')->withPivot('number')
->withTimestamps();
}
コントローラ
$people = new People(array(
'quantity' => $request->get('quantity'),
));
$people->save();
$order->countries()->sync($request->get('id')->attach('quantity'));
「数量」あなたはここに入力ミスがありますか?それはあなたのアプリケーションにありますか? –
@AndyHolmes、それは私のアプリケーションにはありません。おそらく私はここでコードをきれいにしようとしていました。 –