Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Eloquent Many-to-Many-to-Many – wie man Fernbeziehung einfach lädt

So können Sie es tun:

User::where('id', $id)->with(['groups.permissions' => function ($q) use (&$permissions) {
     $permissions = $q->get()->unique();
}])->first();

// then
$permissions; // collection of unique permissions of the user with id = $id