Update a record

@param Number  $id      ID of record
@param Request $request Current http request

@throws MalformedInputException

@return Response $response Result of action with data (if successful)
192339
public function putAction($id, Request $request)
    {
        $response = $this->getResponse();
        $model = $this->getModel();

        $this->restUtils->checkJsonRequest($request, $response, $this->getModel());
        $record = $this->restUtils->validateRequest($request->getContent(), $model);

        // handle missing 'id' field in input to a PUT operation
        // if it is settable on the document, let's set it and move on.. if not, inform the user..
        if ($record->getId() != $id) {
            // try to set it..
            if (is_callable(array($record, 'setId'))) {
                $record->setId($id);
            } else {
                throw new MalformedInputException('No ID was supplied in the request payload.');
            }
        }

        // And update the record, if everything is ok
        if (!$this->getModel()->recordExists($id)) {
            $this->getModel()->insertRecord($record, false);
        } else {
            $this->getModel()->updateRecord($id, $record, false);
        }

        // Set status code
        $response->setStatusCode(Response::HTTP_NO_CONTENT);

        // store id of new record so we dont need to reparse body later when needed
        $request->attributes->set('id', $record->getId());

        return $response;
    }
550047
public function updateAction(Request $request, $id)
    {
        $title = $request->get('title');
        $rawCriteria = json_decode($request->get('criteria'), true);

        $filterManager = $this->get('phlexible_message.filter_manager');

        $filter = $filterManager->find($id);
        $filter->setTitle($title);

        $criteria = new Criteria();
        $criteria->setMode(Criteria::MODE_OR);
        foreach ($rawCriteria as $group) {
            $criteriaGroup = new Criteria();
            $criteriaGroup->setMode(Criteria::MODE_AND);
            foreach ($group as $row) {
                if (!strlen($row['value'])) {
                    continue;
                }

                $criterium = new Criterium($row['key'], $row['value']);
                $criteriaGroup->add($criterium);
            }
            if ($criteriaGroup->count()) {
                $criteria->addCriteria($criteriaGroup);
            }
        }
        $filter->setCriteria($criteria);

        $filterManager->updateFilter($filter);

        return new ResultResponse(true, 'Filter updated');
    }
700982
public function update($id, UpdateRequest $request)
	{
		$level = "danger";
		$message = " You are not permitted to update permissions.";

		if ( Shinobi::can ( config('watchtower.acl.permission.edit', false) ) ) {
			$permission = Permission::findOrFail($id);
			$permission->update($request->all());
			$level = "success";
			$message = "<i class='fa fa-check-square-o fa-1x'></i> Success! Permission edited.";
		}

		return redirect()->route( config('watchtower.route.as') .'permission.index')
				->with( ['flash' => ['message' => $message, 'level' =>  $level] ] );
	}
473072
public function update(LessonUpdateRequest $request, $id)
    {
        try {
            $this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);

//            $lesson = $this->repository->update($id, $request->all());

            $lesson = $this->repository->update($request->all(), $id);

            $response = [
                'message' => 'Lesson updated.',
                'data'    => $lesson->toArray(),
            ];

            if ($request->wantsJson()) {
                return response()->json($response);
            }

            return redirect()->back()->with('message', $response['message']);
        } catch (ValidatorException $e) {
            if ($request->wantsJson()) {
                return response()->json([
                    'error'   => true,
                    'message' => $e->getMessageBag()
                ]);
            }

            return redirect()->back()->withErrors($e->getMessageBag())->withInput();
        }
    }
313427
public function update(Request $request, $id)
    {
        $role = Role::find($id);
        $role->fill($request->all());
        $role->save();

        session()->flash('success' , 'Rol actualizado con exito');
        return redirect()->route('roles.index');
    }
1245960
public function rename($id, Request $request)
    {
        $this->validate($request, ['title' => ['required']]);

        $thread = $this->model()->find($id);

        return $this->updateModel($thread, ['title' => $request->input('title')], 'rename');
    }
126291
public function update(Request $request, $id)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate([
            "countryCode" => 'required|regex:/\d{1,2}/',
            "label" => "required|max:50",
            "phoneNumber" => 'required|regex:/\d{10}/',
        ]);
        $phone = Phone::findOrFail($id);
        $this->authorize('manage', $phone);
        $phone->country_code = $request->countryCode;
        $phone->label = $request->label;
        $phone->phone_number = $request->phoneNumber;
        $this->authorize('manage', $phone);
        $phone->save();
        return fractal($phone, new PhoneTransformer())
            ->withResourceName('phone')
            ->respond();

    }
856823
public function update(Request $request, $id)
    {
        $this->validate($request, [
            'title' => 'required|min:2',
            'description' => 'min:2',
            'deprecated' => 'boolean',
        ]);

        $book = $this->model->findOrFail($id);

        if (! $book->update($request->all())) {
            return json()->internalError('Failed to update !');
        }

        return json()->success('Updated');
    }
50843
public function edit($id): Response
    {
        if ($objectInfo = $this->model->findFirst($id)) {
            $request = $this->request->getPut();

            if (empty($request)) {
                $request = $this->request->getJsonRawBody(true);
            }
            //update
            if ($objectInfo->update($request, $this->updateFields)) {
                return $this->response($objectInfo->toArray());
            } else {
                //didnt work
                throw new Exception($objectInfo->getMessages()[0]);
            }
        } else {
            throw new Exception('Record not found');
        }
    }
1368746
public function update(Request $request, $id)
    {
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate(['name' => 'required|max:128']);
        /** @noinspection PhpUndefinedMethodInspection */
        $location = Location::findOrFail($id);
        $location->name = $request->name;
        $this->authorize('update', $location);
        /** @noinspection PhpUndefinedMethodInspection */
        $location->save();
        return fractal($location, new LocationTransformer())
            ->withResourceName('location')
            ->respond();

    }
12381
public function update($id,Request $request)
    {
        $email = $this->emails->update( $request->all() );

        alert()->success('Email mis à jour');

        return redirect('build/liste/'.$email->list_id);
    }
109842
public function update(Request $request, $id)
    {
        $this->validate($request, [
			'title' => 'required',
			'content' => 'required'
		]);
        $requestData = $request->all();
        
        $page = Page::findOrFail($id);
        $page->update($requestData);

        return redirect('admin/pages')->with('flash_message', 'Page updated!');
    }
376614
public function update(Request $request, $id)
    {
        $this->validate(request(), [
            'name' => 'required|min:3|max:15',
            'email' => 'required|email',
            'password' => 'required|min:4'
        ]);

        $user = Admin::find($id);
        $user->name = request('name');
        $user->email = request('email');
        $user->password = bcrypt(request('password'));
        $user->save();

        session()->flash('success', 'Usuario actualizado con éxito!');
        return redirect()->route('usuarios.index');
    }
1159047
public function update(Request $request, $id)
    {
        $name = \Transliteration::clean_filename(strtolower($request->label));
        $label = $request->label;

        try
        {
          WorkflowState::where('id',$id)->update(['label' => $label, 'name' => $name]);
        }
        catch(\Illuminate\Database\QueryException $e){
            // do what you want here with $e->getMessage();
            return redirect()->route('state')->with('message', 'Error');
        }

        return redirect()->route('state')->with('message', 'Update data success');
    }
1181464
public function update(Request $request, $id)
    {
        $entry = $this->entriesRepository->getById($id, $this->resource);
        $this->validate($request, $this->validationRules($this->resource, $entry));

        $this->entriesRepository->update($id, $request, $this->resource);

        return redirect()->back()->with('success', 'Updated');
    }
301226
public function update(Request $request, $id)
    {
        $rules = [
            "address" => "required|max:256",
            "country" => "required",
            "label" => "required|max:50",
            "municipality" => "required|max:128",
            "postcode" => 'required|regex:/^[0-9]{5}(-\d{4})?$/',
            "stateProvince" => "required",
        ];
        /** @noinspection PhpUndefinedMethodInspection */
        $request->validate($this->addPolymorphicRules($rules, 'addressable', $request->addressableType));
        $address = Address::findOrFail($id);
        $this->authorize('manage', $address);
        $address->label = $request->label;
        $address->address = $request->address;
        $address->municipality = $request->municipality;
        $address->state_province = $request->stateProvince;
        $address->postcode = $request->postcode;
        $address->country = $request->country;
        $address->save();
        return fractal($address, new AddressTransformer())
            ->withResourceName('address')
            ->respond();
    }
1134711
public function update(Request $request, $id)
    {
        $this->validate(
            $request,
            [
                'name' => 'required',
                'email' => 'required|string|max:255|email|unique:users,email,' . $id,
                'roles' => 'required'
            ]
        );

        $data = $request->except('password');
        if ($request->has('password')) {
            $data['password'] = bcrypt($request->password);
        }

        $user = User::findOrFail($id);
        $user->update($data);

        $user->roles()->detach();
        foreach ($request->roles as $role) {
            $user->assignRole($role);
        }

        return redirect('admin/users')->with('flash_message', 'User updated!');
    }