Example #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Group::truncate();
     Group::reguard();
     $groups = $this->groups();
     foreach ($groups as $group) {
         Group::create($group)->givePermissionTo($group['permissions']);
     }
 }
Example #2
0
 /**
  * Create a user and assign it to a group.
  *
  * @param array  $attributes The user attributes.
  * @param Group|int|string $group      Group handle or group model [Optional]
  *
  * @return object
  */
 public function createUser(array $attributes, $group = null)
 {
     // Default group
     if (!$group) {
         $group = $this->groups->findOrFail(config('membership.groups.default'));
     }
     // Get the group by its ID
     if (is_numeric($group)) {
         $group = $this->groups->findOrFail($group);
     } elseif (is_string($group)) {
         $group = $this->groups->whereHandle($group)->firstOrFail();
     }
     // Get user model class name
     $class = config('auth.model') ?: config('auth.providers.users.model');
     // Create the user and assign it to the specific group
     $user = $class::create($attributes);
     $user->assignTo($group);
     return $user;
 }
Example #3
0
 /**
  * Filter users by their group belonging.
  *
  * @param Builder $query
  * @param string  $group
  *
  * @return mixed
  */
 public function scopeOnly(Builder $query, $group)
 {
     return Group::whereHandle($group)->firstOrFail()->users();
 }