can('dcat.admin.users.edit_vip'); } /** * Handle the form request. * * @param array $input * * @return mixed */ public function handle(array $input) { $id = $this->payload['id'] ?? 0; $user = User::findOrFail($id); $vip_id = $input['vip']; try { DB::beginTransaction(); if ($user->userVip) { if ($vip_id) { $user->userVip->update([ 'vip_id' => $vip_id ]); } else { $user->userVip->delete(); } } else { if ($vip_id) { $user->userVip()->create([ 'vip_id' => $vip_id ]); } } DB::commit(); } catch (Throwable $th) { DB::rollBack(); report($th); return $this->response()->error('操作失败:'.$th->getMessage()); } return $this->response()->success(__('admin.update_succeeded'))->refresh(); } /** * Build a form here. */ public function form() { $id = $this->payload['id'] ?? 0; $user = User::findOrFail($id); $vips = Vip::orderBy('sort')->get(); $this->text('user_vip', '当前代理')->value(data_get($user, 'userVip.vip.name', ''))->disable(); $this->select('vip')->options($vips->pluck('name', 'id')); } }