I create a new version of laravel, and in that project there are different kind of models with different kind of attributes,
for those models I want to create a dynamic index page like this,
I include a layout file and pass variables to it such as records, specific column title and value for each of them, but the problem here is that for example and article has multiple relationships like category, author or ...
or for edit route of articles we should pass record to it for route model binding
here is my layout file
@if ($records->count())
<table>
<thead class="text-center">
<tr>
@foreach($fields as $field)
<th scope="col">{{ $field[0] }}</th>
@endforeach
</tr>
</thead>
<tbody class="text-center">
@foreach ($records as $record)
<tr>
@foreach($fields as $field)
<td>{{ $record->{$field[1]} }}</td>
@endforeach
<td>
<a href="{{ route($paths['edit'], $record) }}"><button type="button" class="btn btn-sm btn-primary" rel="tooltip" data-placement="top" title="Edit"><i class="far fa-edit"></i></button></a>
</td>
</tr>
@endforeach
</tbody>
</table>
@endif
and in the other hand in the specific index file for each model we have this code
@include('layouts.index', [
'title' => 'Articles Index',
'records' => $articles,
'fields' => [
[ "Article Title", "title" ],
[ "Category", $record->category->title],
[ "View", "view"],
],
'paths' => [
'edit' => "{{ route('articles.edit', @$record) }}",
],
])
records variable is the collection for model that passes from controller to view fields have array inside it self first item is column title that shown as table thead and second one is the field that should be shown in every row of table for each row of records,
but the problem is that for category we should use the $record variable that will used in 2nd foreach of layout file, but in the specific index of models its not found!
I need a way that blade load this variable in the layout file, not the specific index view of model,
a way that pass code from one blade to another one!!
Hope you help me find a way Regards
</div>