Modules\Doptor\CompanyInfo\Controllers\CompanyController::update PHP Метод

update() публичный Метод

Update the specified resource in storage.
public update ( integer $id ) : Illuminate\Http\RedirectResponse
$id integer
Результат Illuminate\Http\RedirectResponse
    public function update($id)
    {
        if (!can_user_access_company($id)) {
            abort(501);
        }
        $input = Input::all();
        $incharges = $this->fixInchargeData($input['incharge']);
        if (isset($input['form_close'])) {
            return Redirect::to("{$this->link}modules/{$this->module_link}");
        }
        if (isset($input['form_save'])) {
            $redirect = "{$this->link}modules/{$this->module_link}";
        } else {
            $redirect = "{$this->link}modules/{$this->module_link}/companies/create";
        }
        $company_model = $this->module_namespace . "Models\\Company";
        $country_model = $this->module_namespace . 'Models\\Country';
        try {
            $company = $company_model::find($id);
            $company->update($input);
            foreach ($incharges as $incharge) {
                if ($incharge['id']) {
                    // Edit existing incharge
                    $this_incharge = $company->incharges()->find($incharge['id']);
                    $this_incharge->update($incharge);
                } else {
                    // Create new incharge
                    $company->incharges()->create($incharge);
                }
            }
        } catch (ValidationException $e) {
            return Redirect::back()->withInput()->withErrors($e->getErrors());
        }
        if ($company) {
            return Redirect::to($redirect)->with('success_message', trans('success_messages.company_delete'));
        } else {
            return Redirect::back()->with('error_message', trans('error_messages.company_delete'));
        }
    }