/** * Assign the role to the users with the given ids. * * @param \Silber\Bouncer\Database\Role $role * @param array $ids * @return void */ protected function assignRole(Role $role, array $ids) { $existing = $role->users()->whereIn('id', $ids)->lists('id')->all(); $ids = array_diff($ids, $existing); $role->users()->attach($ids); }
/** * Get the IDs of the users that already have the given role. * * @param \Silber\Bouncer\Database\Role $role * @param array $ids * @return \Illuminate\Support\Collection */ protected function getUsersWithRole(Role $role, array $ids) { $model = Models::user(); $column = $model->getTable() . '.' . $model->getKeyName(); return $role->users()->whereIn($column, $ids)->lists($column); }