Sorry, but I'm new to laravel, you're giving this error when I try to view the page: 'Trying to get property' name 'of non-object This is my controller
public function index(){
$medicos = Medico::with("especializacaos")->get();
return view('medicos.index', ['medicos'=>$medicos]);
}
This is my view
<div class="container-fluid">
<h3>Medicos</h3>
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Nome</th>
<th>CRM</th>
<th>ESPECIALIZAÇÃO</th>
</tr>
</thead>
@foreach ($medicos as $m)
<tr>
<td> {{$m->medico->nome}}</td>
<td> {{$m->medico->crm}}</td>
if (count($m->especializacaos ) > 0) {
echo "Especializações: <br>";
echo "<ul>";
foreach($m->especializacaos as $e) {
<td> "<li> Nome da especialização: " . $e->nome . " | ";
"</li>"</td>;
}
echo "</ul>";
}
echo "<hr>"
<td></td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endsection
'Thank you very much for understanding.