/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['customer_name' => 'required']); if ($validator->fails()) { echo "loi"; return; } $data['user_id'] = $request['user_id']; $data['country_id'] = $request['country_id']; $data['customer_name'] = $request['customer_name']; $data['duration'] = $request['duration']; $data['engagement'] = $request['engagement']; $data['head_count'] = $request['head_count']; $data['opportunity_name'] = $request['opportunity_name']; $data['opportunity_type'] = $request['opportunity_type']; $data['probability'] = $request['probability']; $data['closure_date'] = date('Y-m-d H:i:s', strtotime($request['closure_date'])); $data['region'] = $request['region']; $data['vertical'] = $request['vertical']; $data['delivery_location'] = $request['delivery_location']; $data['started_at'] = date('Y-m-d H:i:s', strtotime($request['started_at'])); $data['value'] = $request['value']; $data['service'] = $request['service']; $data['description'] = $request['description']; //$sale = Sale::insert ( $data ); // insert and make value and head count per month $id = DB::table('sales')->insertGetId($data); Sale::makeHcValue($data, $id); // redirect // Session::flash('message', 'Successfully created the sale!'); $sales = Sale::with('user', 'country')->get(); foreach ($sales as $sale) { $sale->load('values'); } return redirect('sale'); }