Laravel 5.8 - Relationship listing

Asked

Viewed 114 times

-1

I have the following code in my controller funcionarios::with('user', 'rh')->get()returns all beautiful related data but only the first record is really related sure the others in the RH relationship does not list the RH data comes without anything an empty array.

Follow the model code:

class funcionarios extends Model
{

    protected $table = 'funcionarios';

    protected $fillable = [
        'sexo',
        'celular',
        'matricula',
        'ramal'
    ];

    protected $hidden = [];


    public function rh()
    {

        return $this->belongsToMany(\App\RH::class, 'funcionario_rh', 'rh_id', 'funcionario_id');

    }

    public function user() {

        return $this->hasOne(\App\User::class, 'id', 'user_id');
    }

}

I leave alerted that the entries are correct in the bank the way they should be done and are registering everything, the real problem is in the listing.

1 answer

-1


I already solved, I made a mistake in Laravel’s relationship the code I put in the question has a reversal in RH_id and funcionario_idchanging the two of place the listing flows perfectly.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.