I'm trying to bring data into a view and I'm not succeeding.
I have my Person class.
class Pessoa extends Model {
public function telefones()
{
return $this->hasMany(Telefone::class);
}
And in my Phone class I have.
class Telefone extends Model
{
public function pessoa()
{
return $this->belongsTo(Pessoa::class);
}
}
migrations are with relationships
Schema::create('pessoas', function (Blueprint $table)
{
// outros relacionamentos e colunas
$table->integer('id_telefone')->unsigned();
$table->foreign('id_telefone')->references('id')->on('telefones');
$table->timestamps();
});
I finally have the data visualization view.
<thead>
<tr>
<th>Nome</th>
<th>Telefone</th>
</tr>
</thead>
@foreach($pessoasfisicas as $pessoafisica)
<tbody>
<tr>
<td>{{$pessoafisica->nome}}</td>
@foreach($pessoafisica->telefones() as $tel)
<td>{{ $tel->telefone }}</td>
@endforeach
<td><h4>
</tr>
</tbody>
@endforeach
When the data that is returned is not returning the phone, there is some improvement in this example to solve.