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