/** * Migrate the data from the user_abilities table. * * @return void */ protected function migrateUserAbilities() { $pivots = DB::table('user_abilities')->get(); $type = Models::user()->getMorphClass(); $records = array_map(function ($pivot) use($type) { return ['ability_id' => $pivot->ability_id, 'entity_type' => $type, 'entity_id' => $pivot->user_id]; }, $this->toArray($pivots)); DB::table('permissions')->insert($records); }
/** * Clear the cache. * * @param null|int|\Illuminate\Database\Eloquent\Model $user * @return $this */ public function refresh($user = null) { if (!is_null($user)) { return $this->refreshFor($user); } if ($this->cache instanceof TaggedCache) { $this->cache->flush(); return $this; } foreach (Models::user()->lists('id') as $id) { $this->refreshFor($id); } return $this; }
/** * Get the table name for the user model. * * @return string */ protected function users() { return Models::user()->getTable(); }
/** * Set the classname of the user model to be used by Bouncer. * * @return void */ protected function setUserModel() { $config = $this->app->make('config'); $model = $config->get('auth.providers.users.model', function () use($config) { return $config->get('auth.model', \App\User::class); }); Models::setUsersModel($model); Models::setTables(['users' => Models::user()->getTable()]); }
/** * Refresh the cache for all roles and users, iteratively. * * @return void */ protected function refreshAllIteratively() { foreach (Models::user()->all() as $user) { $this->refreshFor($user); } foreach (Models::role()->all() as $role) { $this->refreshFor($role); } }
/** * Refresh the cache for all users, iteratively. * * @return $this */ protected function refreshForAllUsersIteratively() { $user = Models::user(); foreach ($user->lists($user->getKeyName()) as $id) { $this->refreshFor($id); } return $this; }
/** * 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); }