Modules\Doptor\CompanyInfo\Controllers\CompanyController::store PHP Method

store() public method

Store a newly created resource in storage.
public store ( )
    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'));
        }
    }