/** * @param $id * @param bool $withPermissions * @throws GeneralException * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static */ public function findOrThrowException($id, $withPermissions = false) { if (!is_null(Role::find($id))) { if ($withPermissions) { return Role::with('permissions')->find($id); } return Role::find($id); } throw new GeneralException('That role does not exist.'); }
/** * @param $id * @param bool $withPermissions * @throws GeneralException * @return \Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection|null|static */ public function findOrThrowException($id, $withPermissions = false) { if (!is_null(Role::find($id))) { if ($withPermissions) { return Role::with('permissions')->find($id); } return Role::find($id); } throw new GeneralException(trans('exceptions.backend.access.roles.not_found')); }
/** * Set up tests. */ public function setUp() { parent::setUp(); // Set up the database Artisan::call('migrate:refresh'); Artisan::call('db:seed'); // Run the tests in English App::setLocale('en'); /** * Create class properties to be used in tests */ $this->admin = User::find(1); $this->executive = User::find(2); $this->user = User::find(3); $this->adminRole = Role::find(1); $this->executiveRole = Role::find(2); $this->userRole = Role::find(3); }
/** * Run the database seed. * * @return void */ public function run() { if (DB::connection()->getDriverName() == 'mysql') { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); } if (DB::connection()->getDriverName() == 'mysql') { DB::table(config('access.permission_role_table'))->truncate(); } elseif (DB::connection()->getDriverName() == 'sqlite') { DB::statement('DELETE FROM ' . config('access.permission_role_table')); } else { //For PostgreSQL or anything else DB::statement('TRUNCATE TABLE ' . config('access.permission_role_table') . ' CASCADE'); } /** * Assign view backend and manage user permissions to executive role as example */ Role::find(2)->permissions()->sync([1, 2]); /** * */ if (DB::connection()->getDriverName() == 'mysql') { DB::statement('SET FOREIGN_KEY_CHECKS=1;'); } }