Users and articles are one to many relationship database.
if I use owner instead on user in article model, we should add the foreign key such as:
class Article extent model
{
public owner() {
return $this->belongsTo('User', 'user_id');
}
}
in the controller or view we can use
$article->owner->name;
No comments:
Post a Comment