/** * 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)); } }
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; }