I have a problem retrieving data from a third table, as you can see I have three tables:
- Models : id , code , title
- levels : id , code . title
- models_level : model_id,level_id
I have as function :
$model = model::paginate(10);
$level = level::all();
$models_level = models_level::all();
return view('pg',compact('model','level','models_level'));
How can I retrieve the level name based on the model id retrieved?
Here is my blade
<tbody>
@foreach($model as $f)
<tr class="item{{$f->id}}">
<td style="font-size: 13px;"> {{$f->title}}</td>
<td style="font-size: 13px;">{{$f->code}}</td>
<td style="font-size: 13px;">{{$f->models_level->level_id}}</td>
</tr>
@endforeach
{{ $filiere->links() }}
</tbody>
I need to show the title in level instead of the ID.
in this case I have 2 different tables and the 3 rd is associative table that contains the two , so I have to pass by model to get model_level . get the level id depending on the model_id and the go to level and find the title ..