Skip to content

Instantly share code, notes, and snippets.

@SeoRoman
Forked from anonymous/gist:a33f2843f0bd9cfd2a70
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeoRoman/0e4d0845c28c74ca99f2 to your computer and use it in GitHub Desktop.
Save SeoRoman/0e4d0845c28c74ca99f2 to your computer and use it in GitHub Desktop.
// 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