Answer the question
In order to leave comments, you need to log in
How to get username using Eloquent ORM?
There is the following scheme: Post - User
From the post we get the value of author (user id) and this value must be passed to the Users table, displaying the nickname. How I did it:
Post.php model
public function author() {
return $this->belongsTo(User::class);
}
public function post() {
return $this->hasMany(Post::class);
}
$author = User::where('id', $post['author'])->first();
Answer the question
In order to leave comments, you need to log in
Solution: it was necessary to specify foreignkey 'author' and ownerkey 'id' :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question