vendredi 29 avril 2016

Laravel 5.2 - Multiple relations

Dear Laravel Professionals,

This is my first Laravel 5 project.

DB tables Image

I have a 'members'-function in my Group controller with the following code:

public function members() {
    return $this->belongsToMany('App\User', 'group_members')->withPivot('status', 'right_id')->withTimestamps();
}

When I call this function it will return the members of a specific function.

Now I want to call a function called 'rights' or something like that, which will return the right_id and the type of the 'rights' table in a single line of code.

Now when I want the right_id of a member I use this line:

$group->members->where('id', Auth::user()->id)->first()->pivot->right_id == 2

But then I dont have the 'rights'-type because the right_id is in the 'group_members'-table.

I want it to work something like this:

$group->members->where('id', Auth::user()->id)->first()->rights

I hope that this is enough information to give me some advice, or even a solution for this problem.

I know this could also be done by making a custom query, but I like the way Laravel works.

Thanks in advance.

Theo.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1rnloRV
via IFTTT

Aucun commentaire:

Enregistrer un commentaire