0
I need some information about running two tables through the index. I have the following code in the controller:
public function index(){
$tabela = capitulo::orderby('id', 'desc')->paginate();
$tabela1 = documentacao::orderby('id', 'desc')->paginate();
return view('gestao-documental.index', ['itens' => $tabela, 'itens1' => $tabela1]);
}
And I want to pass the data of the two tables :: Chapter (ID, chapter) :: Documentation(ID, Chapter, Document, version) for the following datatable
<div class="card shadow mb-4">
<div class="card-body">
<div class="table-responsive">
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
@foreach($itens as $item)
<tr>
<th> {{$item->capitulo}} </th>
</tr>
</thead>
<tbody>
@foreach($itens1 as $item1)
<tr>
<td> {{$item1->documentacao}} </td>
</tr>
@endforeach
</tbody>
@endforeach
</table>
</div>
</div>
Can you post the relationship code of the eloquent model? What you need is, it seems to me, a loop inside another, but you need to know what the data and relationships are to be effective in helping
– Ademir Mazer Jr - Nuno
I changed the question a little. I hope it is a little more complete.
– ChrisAdler
But the table and Tabela1, chapters and documentation relate in the bank? If yes and you need, for example, to put cap inside doc or vice versa, you need, in addition to being correct the modeling in the database, to use Relations in your models to be able to recover the related records of a "parent" record ... can add model codes and modeling this part of the bank?
– Ademir Mazer Jr - Nuno
They are related (Foreign key). That is, the main table (chapter) is always necessary to create data in the documentation table. is the only link that the tables have is Id_documentacao. I do not know if I could explain well .
– ChrisAdler
so you need to add Relationship methods to the models and navigate correctly on Blade, I’ll put an example below
– Ademir Mazer Jr - Nuno