Problem returning data in view with laravel 5

1

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.

    
asked by anonymous 14.07.2016 / 20:40

1 answer

0

I think your migration is wrong. The person id that should be in the Phone table, not the other way around.

    
14.07.2016 / 21:16