Пример #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $name = $this->argument('name');
     $cmt = $this->argument('description');
     $role = new AclRole();
     $role->name = $name;
     $role->comment = $cmt;
     $role->save();
     $this->info('saved: ' . $role->id);
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $roleName = $this->argument('role');
     $roleModel = AclRole::whereName($roleName)->first();
     if (!$roleModel) {
         $this->error($msg = "the role {$roleName} does not exists");
         throw new \InvalidArgumentException($msg);
     }
     $userIds = $this->argument('user_id');
     foreach ($userIds as $uid) {
         $rel = new AclUserRole();
         $rel->user_id = $uid;
         $rel->role_id = $roleModel->id;
         $rel->save();
         $this->info(sprintf('role: %d, user: %d, rel: %d', $roleModel->id, $uid, $rel->id));
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $role = $this->argument('role');
     $roleModel = AclRole::whereName($role)->first();
     if (!$roleModel) {
         $this->error($msg = "the role {$role} does not exists");
         throw new \InvalidArgumentException($msg);
     }
     $permission_args = $this->argument('permission');
     $permModes = AclPermission::whereIn($this->option('unique-tag') ? 'unique_tag' : 'id', $permission_args)->get();
     foreach ($permModes as $pm) {
         $rel = new AclRolePermission();
         $rel->role_id = $roleModel->id;
         $rel->permission_id = $pm->id;
         $rel->save();
         $this->info(sprintf('role: %d, perm: %d, rel: %d', $roleModel->id, $pm->id, $rel->id));
     }
 }
Пример #4
0
 private function getRoles()
 {
     if (!$this->roles) {
         $this->roles = AclRole::whereIn('id', function ($query) {
             /** @var $query \Illuminate\Database\Query\Builder */
             $query->select('role_id')->from(AclUserRole::tableName())->where('user_id', $this->adminId);
         })->get();
     }
     return $this->roles;
 }