public function store()
{
$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";
}
if ($this->module_vendor) {
$company_model = "Modules\\{$this->module_vendor}\\{$this->module_alias}\\Models\\Company";
} else {
$company_model = "Modules\\{$this->module_alias}\\Models\\Company";
}
try {
$company = $company_model::create($input);
foreach ($incharges as $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_create'));
} else {
return Redirect::back()->with('error_message', trans('error_messages.company_create'));
}
}