1
I’m trying to bring data to a view and I’m not succeeding.
I have my class of Person.
class Pessoa extends Model {
public function telefones()
{
return $this->hasMany(Telefone::class);
}
and in my Telephone 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();
});
finally I have the view of data visualization.
<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 data is returned is not returning the phone, there is some improvement in this example to solve.
I don’t really know what I was doing, there was a blackout and I ended up writing wrong.
– André Martins