Answer the question
In order to leave comments, you need to log in
What is the best way to display username by id in laravel?
The question is how to do it right:
I have an index.blade file where the news is displayed:
id | title | body | author
1 | www | www | 1
2 | avy | fivw| 1
How to display the name of the author instead of 1 if I have a function in the model:
public static function author($id){
return $author=DB::table('users')->where('id',$id)->select('name');
}
@forelse($news as $item)
<tr>
<td>{{ $item->id }}</td>
<td>{{ $item->title }}</td>
<td>{{ $item->body }}</td>
<td>{{ \App\News::author($item->author) }}</td>
</tr>
@endforelse
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question