public function update($id)
{
$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}/branches/create";
}
$company_branch_model = $this->module_namespace . "Models\\CompanyBranch";
$country_model = $this->module_namespace . 'Models\\Country';
try {
$company_branch = $company_branch_model::find($id);
$company_branch->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_branch) {
return Redirect::to($redirect)->with('success_message', trans('success_messages.company_branch_update'));
} else {
return Redirect::back()->with('error_message', trans('error_messages.company_branch_update'));
}
}