3
I have two tables that are already listed on MySQL
and use Laravel
, I am already persisting the information in the bank. When I record a news, it is already assigned to the author normally (tables autor
and news
).
When it comes to listing news
, I did the following method on NewsControllers
public function listar()
{
$news= News::all();
return view('listar')->with('news', $news);
}
There when I want to display them in the views, I do
@foreach ($news $n)
<tr>
<td>{{ $n->id}}</td>
<td>{{ $n->conteudo}}</td>
</tr>
@endforeach
And you work perfectly.
My question would be, how to display the author’s name in that listing and in that listing method?
[news]
id
titulo
conteudo
autor (FK com id de autores)
[authors]
id
nome
I put an answer, but what I needed was to see the two models you quoted in your question, have how to put them?
– novic
But his model is automatic, in my bag
– Roberta
Or what it’s called when my model has just this: <?php namespace App; use Illuminate Database Eloquent Model; class News extends Model { protected $table = 'news'; public $stamptimes = true; }
– Roberta
the class you inherit from Eloquent for CRUD (INSERT, UPDATE, DELETE and DELETE) operations, that’s all you have?
– novic
Yeah, that’s all!
– Roberta
what is the class of Authors?
– novic
I realized that all your questions have answers and that they were not accepted by you, it would be nice @Roberta to do this, read this: https://answall.com/help/privileges/vote-up and https://answall.com/help/why-vote please do not fail to accept the answers if they suit you!
– novic