/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(UpdateClientRequest $request) { $client = $this->clientService->save($request->input()); Session::flash('message', trans('texts.updated_client')); return redirect()->to($client->getRoute()); }
/** * @SWG\Put( * path="/clients/{client_id}", * tags={"client"}, * summary="Update a client", * @SWG\Parameter( * in="body", * name="body", * @SWG\Schema(ref="#/definitions/Client") * ), * @SWG\Response( * response=200, * description="Update client", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function update(UpdateClientRequest $request, $publicId) { if ($request->action == ACTION_ARCHIVE) { try { $client = Client::scope($publicId)->withTrashed()->firstOrFail(); } catch (ModelNotFoundException $e) { return $this->errorResponse(['message' => 'Record not found'], 400); } $this->clientRepo->archive($client); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); } else { if ($request->action == ACTION_RESTORE) { $client = Client::scope($publicId)->withTrashed()->first(); if (!$client) { return $this->errorResponse(['message' => 'Client not found.']); } $this->clientRepo->restore($client); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); } } $data = $request->input(); $data['public_id'] = $publicId; $this->clientRepo->save($data); $client = Client::scope($publicId)->with('country', 'contacts', 'industry', 'size', 'currency')->first(); if (!$client) { return $this->errorResponse(['message' => 'Client not found.']); } $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); }
/** * @SWG\Put( * path="/clients/{client_id}", * tags={"client"}, * summary="Update a client", * @SWG\Parameter( * in="body", * name="body", * @SWG\Schema(ref="#/definitions/Client") * ), * @SWG\Response( * response=200, * description="Update client", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function update(UpdateClientRequest $request) { $client = $this->clientService->save($request->input()); $client = Client::scope($client->public_id)->with('country', 'contacts', 'industry', 'size', 'currency')->first(); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); }
/** * @SWG\Put( * path="/clients/{client_id}", * tags={"client"}, * summary="Update a client", * @SWG\Parameter( * in="body", * name="body", * @SWG\Schema(ref="#/definitions/Client") * ), * @SWG\Response( * response=200, * description="Update client", * @SWG\Schema(type="object", @SWG\Items(ref="#/definitions/Client")) * ), * @SWG\Response( * response="default", * description="an ""unexpected"" error" * ) * ) */ public function update(UpdateClientRequest $request, $publicId) { if ($request->action == ACTION_ARCHIVE) { $client = Client::scope($publicId)->firstOrFail(); $this->clientRepo->archive($client); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); } $data = $request->input(); $data['public_id'] = $publicId; $this->clientRepo->save($data); $client = Client::scope($publicId)->with('country', 'contacts', 'industry', 'size', 'currency')->first(); $transformer = new ClientTransformer(Auth::user()->account, Input::get('serializer')); $data = $this->createItem($client, $transformer, ENTITY_CLIENT); return $this->response($data); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(UpdateClientRequest $request) { $data = $request->input(); if (!$this->checkUpdatePermission($data, $response)) { return $response; } $client = $this->clientService->save($data); Session::flash('message', trans('texts.updated_client')); return redirect()->to($client->getRoute()); }