public function postTargetassign(Request $request) { $rules = array('employeeid' => 'required', 'eventname' => 'required', 'target_value' => 'required', 'target_date' => 'required', 'currency' => 'required', 'modeoftarget' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return redirect('targetmodule/assigntarget')->withErrors($validator); } else { $data = Input::get(); $now = date('d-m-Y'); $targetdata = Targetassign::where('Eventname', $data['eventname'])->where('Employeeid', $data['employeeid'])->get(); // dd(count($targetdata)) ; if (count($targetdata) == 0) { $c = new Targetassign(); $c->Employeeid = $data['employeeid']; $c->Eventcode = $data['eventname']; $c->Targetvalue = $data['target_value']; $c->Currency = $data['currency']; $c->Targetdate = $data['target_date']; $c->Targetassigned = $now; $c->Modeoftarget = $data['modeoftarget']; $c->save(); } else { return redirect('targetmodule/assigntarget')->with('target_error', true); } } $request->session()->flash('alert-success', 'Target Has Been Assigned Successfully'); return redirect('targetmodule/assigntarget'); // }