lundi 19 octobre 2015

Laravel 5: show value with far away relationship

I have a doubt and sure you can help me.

If I have a table user with 'work_id' row, and this value is a releated foreing key with the 'id' into 'work' table.

And into 'work' table I have a 'work_competence_id', and is a foreing key to 'work_competence' table.

And into 'work_competece' I have other row, 'competence_id', that is other foreing key, releated with the 'id' value into 'competence' table...

How can I get competence 'name' (for example) into my view.

I made some easy things, like show the work's name of each user, using

public function work()
{
    return $this->hasOne('App\Work', 'id', 'work_id');
}

I put this code into User model. And I use it into view with:

{{ $user->work->name }} 

But, how is possible to do with so many relationships like I comment above??

Thank you!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire