Laravel 有很多和属于参数
我有一个表格存储,存储有很多库,在库中我有存储的外键。store_id
存储表
id(PK)
库表
id(PK)
store_id(FK)
我对它说的文档中的参数感到困惑,并且参数包括hasMany
belongsTo
返回 $this->hasMany('App\Comment', 'foreign_key');
返回 $this->hasMany('App\Comment', 'foreign_key', 'local_key');
返回 $this->belongsTo('App\Post', 'foreign_key', 'other_key');
哈斯多foreign_key和local_key来自哪一张桌子?与属于属于哪个表foreign_key和other_key来自哪个表?
商店模式
public function library(){
return $this->hasMany('App\Library', 'what_foreign_key_should_be_here','what_other_key_should_be_here');
}
库模型
public function stores(){
return $this->belongsTo('App\Stores', 'what_foreign_key_should_be_here', 'what_other_key_should_be_here');
}
因为有时我会将表的主键ID更改为其他名称,如sid,所以我总是想指定哪个是外键和主键