BelongsToMany relationship allows you to define which model key will be used in pivot table.
Primary Key is the default, but you can override it using:
class Rule {
public function websites()
{
return $this->belongsToMany(Website::class, 'rule_website', 'rule_id', 'website_code', 'id', 'code');
}
}
AttachMany fields send ids to the controller and use sync method to attach/detach related models.
It should use relatedKey (code in the example) instead of id.
BelongsToMany relationship allows you to define which model key will be used in pivot table. Primary Key is the default, but you can override it using:
AttachMany fields send ids to the controller and use
sync
method to attach/detach related models. It should use relatedKey (code
in the example) instead of id.