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

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?

0

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

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.