/** * * @param type $_id * @return \Illuminate\View\View Description */ public function save($_id = null) { $contract = Contract::findOrNew($_id); # Validations $rules = array('code' => 'required|unique:contracts,code,' . $_id); $fields = Input::all(); $validator = Validator::make(Input::all(), $rules); $contract->code = $fields['code']; $contract->id = $_id; $contract->customer_id = $fields['customer_id']; $contract->value = str_replace('.', '', $fields['value']); $contract->value = str_replace(',', '.', $contract->value); $date = explode(' ', $fields['date']); $date_2 = explode('/', $date[0]); $contract->date = date('Y-m-d H:i:s', strtotime("{$date_2[2]}-{$date_2[1]}-{$date_2[0]}")); if (!$validator->fails()) { $contract->save(); } else { $contract->_error = 'Código já cadastrado!'; return View::make('site.contract.form', ['contract' => $contract]); } return Redirect::to('/contract'); }