-
-
Save SeoRoman/0e4d0845c28c74ca99f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Model User.php | |
public function groups() | |
{ | |
return $this->belongsToMany('SARP\UserGroup','users_groups', 'user_id', 'group_id'); | |
} | |
// Model UserGroup.php | |
public function users() | |
{ | |
return $this->belongsToMany('SARP\User', 'users_groups', 'group_id', 'user_id'); | |
} | |
$group = \Auth::User->groups->first(); // First Group | |
dd($group->name); | |
$groups = \Auth::User->groups; // All Groups | |
foreach($groups as $group) | |
{ | |
echo $group->name . "<BR>"; | |
} | |
dd(); | |
// I didn't do for the other Model because I don't need atm. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment