Consider this relation:
// in Post model
public function user()
{
return $this->belongsTo('App\Models\Post');
}
I think $post->user->name
should be enough to get the name of post's owner. However $post->user
return the user id instead of the user model. So I have to use:
$post->user()->first()->name;
Shouldn't $post->user
return the post's owner?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire