【发布时间】:2016-10-12 14:43:57
【问题描述】:
好吧,我看过一些关于这个的帖子,但我根本不明白附加的概念,我有三个表:
列表(列表):
$table->increments('id');
$table->string('nom_llista');
$table->integer('user_id')->unsigned();
});
Cancons(歌曲):
$table->increments('id');
$table->string('titol');
$table->integer('genere_id')->unsigned();
$table->integer('artista_id')->unsigned();
$table->integer('album_id')->unsigned();
数据透视表:llistes_cancons (lists_songs):
$table->increments('id');
$table->integer('id_canco')->unsigned();
$table->integer('id_llista')->unsigned();
$table->timestamps();
我还有两个我认为是正确的课程,但我不确定:
在 Canco.php (Song.php) 中:
public function llistescancons_llistes()
{
return $this->belongsToMany('App\Llista');
}
在Llista.php(List.php)中:
public function llistescancons_cancons()
{
return $this->belongsToMany('App\Canco');
}
所以,问题是我如何在我的控制器中实现一个函数,让我向数据透视表添加新记录(多对多),如果有可能显示记录的另一个功能,我是 Laravel 的新手和对我来说有点难。
【问题讨论】:
标签: laravel-5 eloquent many-to-many attachment record