Beispiel #1
0
 /**
  * Set up the tests
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Role::observe(new AddSlugAttribute());
     User::observe(new UserObserver());
     Permission::observe(new PermissionObserver());
 }
 /**
  * Register any other events for your application.
  *
  * @return void
  */
 public function boot()
 {
     $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
     Role::observe(new AddSlugAttribute());
     User::observe(new UserObserver());
     Permission::observe(new PermissionObserver());
 }
Beispiel #3
0
 /**
  * Apply the given action to the provided roles.
  *
  * @param  string  $action
  * @param  array  $roles
  * @return \Illuminate\Database\Eloquent\Model
  */
 private function applyToRoles(string $action, array $roles)
 {
     if (array_every($roles, 'is_string')) {
         $roles = Role::whereIn('slug', $roles)->get()->toArray();
     }
     call_user_func_array([$this->roles(), $action], [array_pluck($roles, 'id')]);
     return $this->fresh();
 }
 /**
  * Run the seeder.
  *
  * @return void
  */
 public function run()
 {
     $roles = [['name' => 'Administrator'], ['name' => 'Standard']];
     $administrator = Role::create(['name' => 'Administrator']);
     $standard = Role::create(['name' => 'Standard']);
     $administrator->allow('*');
     $standard->allow('*', $priority = 1);
     $standard->deny('admin.*', $priority = 1);
     $standard->deny('api.*', $priority = 1);
 }
Beispiel #5
0
 /** @test **/
 function it_returns_the_administrator_role()
 {
     factory(Role::class)->create(['name' => 'Administrator']);
     $role = Role::admin();
     $this->assertEquals('Administrator', $role->name);
 }
 /**
  * Display all the roles.
  *
  * @param  Request  $request
  * @return \Illuminate\Contracts\View\View
  */
 public function index(Request $request)
 {
     $limit = $request->limit ?? 10;
     $roles = $this->role->paginate($request->limit);
     return view('gate-admin::roles.index', compact('limit', 'roles'));
 }