【问题标题】:how to create laravel 6 pivot table with multi-word如何使用多词创建 laravel 6 数据透视表
【发布时间】:2020-02-06 11:22:20
【问题描述】:
我有 Accounts 表和 Site_links 表。当我在帐户模型中使用此代码时:
public function site_links(){
return $this->belongsToMany($SitelinkModel, 'account_site_link', 'account_id', 'site_link_id')->withTimestamps();
}
两个ID的值是相反的。
【问题讨论】:
标签:
php
laravel
pivot-table
database-migration
database-relations
【解决方案1】:
我得到了答案,所以问题是
belonsToMany 参数必须是这样的 (Model, id_num_of_this_table, id_num_of_the_other_table);
我的帐户模型中的示例
public function site_links(){
return $this->belongsToMany($SitelinkModel, 'account_site_link', 'site_link_id', 'account_id')->withTimestamps();
}