У меня есть таблица с 3 ID из других столбцов. Как подключить более 2 ID? I Не знаю, как приложить три ключа. Когда я пытаюсь сделать «$ weather-> parks() -> attach ('1') -> users() -> attach ('2'); он не прикрепляет park_id. Пожалуйста, помогите.Laravel 5 multiple attach
Schema::create('weather_user_park', function (Blueprint $table) {
$table->integer('weather_id')->unsigned();
$table->integer('park_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->foreign('weather_id')->references('id')->on('weathers');
$table->foreign('park_id')->references('id')->on('parks');
$table->foreign('user_id')->references('id')->on('users');
});
У меня также есть 3 модели:
Park.php
public function weathers()
{
return $this->belongsToMany('App\Weather', 'weather_user_park');
}
public function users()
{
return $this->belongsToMany('App\User', 'weather_user_park');
}
User.php
public function weathers()
{
return $this->belongsToMany('App\Weather', 'weather_user_park');
}
public function parks()
{
return $this->belongsToMany('App\Park', 'weather_user_park');
}
Weather.php
public function users()
{
return $this->belongsToMany('App\User', 'weather_user_park');
}
public function parks()
{
return $this->belongsToMany('App\Park', 'weather_user_park');
}
вы пробовали не Цепочка методы, что путь? и просто назовите его отдельно ?. – Gntem