L
L
lynnikvadim2015-07-30 06:48:09
Laravel
lynnikvadim, 2015-07-30 06:48:09

How to get username by id in Laravel?

Please advise in this situation.
When creating a post, the id of the user who created this post is also recorded in the database.
How can I specify the author not his id but his name when displaying a list of articles?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Plisko, 2015-07-30
@AmdY

Post::find($postId)->author->name;
Post::with('author')->find($postId)->author->name;

laravel.com/docs/4.2/eloquent#relationships

V
Vitaly Inchin ☢, 2015-07-30
@In4in

Use JOINs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question