Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

It appears that a hasManyThrough relationship will not work with a pivot table, is this correct?

This seems to be working but I have no idea if it's the correct way of doing it:

        $roles = Auth::user()->role()->with('permission')->get();
        foreach ($roles as $role)
            foreach ($role->permission as $permission)
                echo $permission->slug;

Is this the proper way of doing this?


look at Belongs to, you might need to do several of those on the models


Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.