0
I’m trying to pull the information from this relationship as you can see below:
Model:
public function endereco(){
return $this->belongsTo('App\Models\End\Logradouro_Bairro');
}
public function local(){
return $this->hasMany('App\Models\Admin\Local');
}
Controller:
public function indexLocal()
{
$local = Local::all();
$secretaria = UnidadeOrganizacional::all();
$endereco = Logradouro_Bairro::all();
return view('admin.local')->with('local',$local)->with('secretaria',$secretaria)->with('endereco',$endereco);
}
View
@foreach($endereco as $loc)
<tr data-id="{{ $loc->id }}" data-sec="{{ $loc->secretaria_id }}">
<td>{{ $loc->secretaria->sigla }}</td>
<td>{{ $loc->nomeDoLocal }}</td>
<td>{{ $loc->endereco->id }}</td>
<td>{{ $loc->telefone }}</td>
<td>{{ $loc->telefone2 }}</td>
<td>{{ $loc->telefone3 }}</td>
<td>{{ $loc->telefone4 }}</td>
<td><i class="material-icons editar md-color-cyan-700" style="font-size:16px; cursor:pointer;" data-toggle="modal" data-target="#myModal5"></i></td>
<td><i class="deletar fa fa-times md-color-red-400" style="font-size:16px; cursor:pointer;" data-toggle="modal" data-target="#myModal6"></i></td>
</tr>
@endforeach
Error:
Trying to get property of non-object in 13cbbd34b07174638fff7aab751ea42a1099d2cf.php line 121 at HandleExceptions->handleError('8', 'Trying to get property of non-object', 'C:\laragon\www\feed\storage\framework\views\13cbbd34b07174638fff7aab751ea42a1099d2cf.php', '121', array('__path' => 'C:\laragon\www\feed\storage\framework\views/13cbbd34b07174638fff7aab751ea42a1099d2cf.php', '__data' => array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'local' => object(Collection), 'secretaria' => object(Collection), 'endereco' => object(Collection)), 'obLevel' => '1', '__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'local' => object(Collection), 'secretaria' => object(Collection), 'endereco' => object(Collection), 'sec' => object(UnidadeOrganizacional), 'end' => object(Logradouro_Bairro), 'loc' => object(Logradouro_Bairro))) in 13cbbd34b07174638fff7aab751ea42a1099d2cf.php line 121 at include('C:\laragon\www\feed\storage\framework\views\13cbbd34b07174638fff7aab751ea42a1099d2cf.php') in PhpEngine.php line 42 at PhpEngine->evaluatePath('C:\laragon\www\feed\storage\framework\views/13cbbd34b07174638fff7aab751ea42a1099d2cf.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'local' => object(Collection), 'secretaria' => object(Collection), 'endereco' => object(Collection))) in CompilerEngine.php line 59 at CompilerEngine->get('C:\laragon\www\feed\resources\views/admin/local.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'local' => object(Collection), 'secretaria' => object(Collection), 'endereco' => object(Collection))) in View.php line 149
This error is presented whenever I try to access the relationship, it works if I use as array:
{{ $loc->enderero['id'] }}
However this doesn’t help because I’m taking the id only as a test, actually I need to go deeper in this relationship:
{{ $loc->endereco->logradouro->nome }}
Has anyone ever had this kind of problem? Could you help me?
If you use
{{ $loc->enderero['logradouro']['nome'] }}
won’t work?– Leonardo
enderero
this correct?– RFL
Put the 3 models in your question...
– novic