/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(VehicleRequest $request)
 {
     $input = $request->all();
     $user_id = '1';
     $vehicle = new Vehicle();
     $vehicle->customer_id = $input['customer_id'];
     $vehicle->reg_no = $input['reg_no'];
     $vehicle->make = $input['make'];
     $vehicle->model = $input['model'];
     $vehicle->year = $input['year'];
     $vehicle->chasis_no = $input['chasis_no'];
     $vehicle->next_service = $input['next_service'];
     $vehicle->created_by = $user_id;
     $vehicle->save($request->all());
     return redirect('/estimates/create');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(EstimateRequest $request)
 {
     $user_id = '1';
     $input = $request->all();
     if ($input['vehicle_id'] != null) {
         $estimate = new Estimate();
         $estimate->customer_id = $input['customer_id'];
         $estimate->vehicle_id = $input['vehicle_id'];
         $estimate->mileage_in = $input['mileage_in'];
         $estimate->department = $input['department'];
         $estimate->net_amount = $input['net_amount'];
         $estimate->created_by = $user_id;
         /*$estimate_detail = new EstimateDetail();
           $estimate_detail->item_id = $input['item_id'];
           $estimate_detail->item_description = $input['item_description'];
           $estimate_detail->units = $input['units'];
           $estimate_detail->rate = $input['rate'];
           $estimate_detail->initial_amount = $input['amount'];*/
         /*$estimate_detail->item_id = 1;
           $estimate_detail->item_description = 'asdqwe';
           $estimate_detail->units = 10;
           $estimate_detail->rate = 10;
           $estimate_detail->initial_amount = 100;*/
         /*$records = [new EstimateDetail([
               'item_id' => $input['item_id'],
               'item_description' => $input['item_description'],
               'units' => $input['units'],
               'rate' => $input['rate'],
               'amount' => $input['amount']
           ])];*/
         /*$num_elements = 0;
           $estimate_detail = array();
           while($num_elements < count($input['item_id']))
           {
               $estimate_detail[] = array(
               'item_id' => $input['item_id'][$num_elements],
               'item_description' => $input['item_description'][$num_elements],
               'units' => $input['units'][$num_elements],
               'rate' => $input['rate'][$num_elements],
               'amount' => $input['amount'][$num_elements]
               );
               $num_elements++;
           }*/
         $estimate->save($request->all());
         for ($i = 0; $i < count($input['item_id']); $i++) {
             $estimate_detail = new EstimateDetail();
             $estimate_detail->item_id = $input['item_id'][$i];
             $estimate_detail->item_description = $input['item_description'][$i];
             $estimate_detail->units = $input['units'][$i];
             $estimate_detail->rate = $input['rate'][$i];
             $estimate_detail->initial_amount = $input['amount'][$i];
             $estimate->estimate_details()->save($estimate_detail);
         }
         /*
                     $data = [];
                     for($i=0;$i<count($input['item_id']);$i++)
                     {
                         $data[] = array(
                             'estimate_id' => $estimate_id,
                             'item_id' => $input[$i]['item_id'],
                             'item_description' => $input[$i]['item_description'],
                             'units' => $input[$i]['units'],
                             'rate' => $input[$i]['rate'],
                             'amount' => $input[$i]['amount']
                         );
                     }
                     EstimateDetail::insert($data);*/
         //DB::table('estimate_details')->insert($data);
         //$estimate->estimate_details()->save($estimate_detail);
         //$estimate->estimate_details()->save($estimate_detail);
         //foreach($records as $record){
         //$estimate->estimate_details()->saveMany($records);
         // }
     } else {
         /*$vehicle = Vehicle::create([
               'customer_id' => $request->get('customer_id'),
               'reg_no' => $request->get('reg_no'),
               'make' => $request->get('make'),
               'model' => $request->get('model'),
               'created_by' => $user_id
           ]);*/
         $vehicle = new Vehicle();
         $vehicle->customer_id = $input['customer_id'];
         $vehicle->reg_no = $input['reg_no'];
         $vehicle->make = $input['make'];
         $vehicle->model = $input['model'];
         $vehicle->created_by = $user_id;
         //$vehicle->save($request->all());
         $estimate = new Estimate();
         $estimate->customer_id = $input['customer_id'];
         $estimate->mileage_in = $input['mileage_in'];
         $estimate->department = $input['department'];
         $estimate->net_amount = $input['net_amount'];
         $estimate->created_by = $user_id;
         $vehicle->save($request->all());
         $vehicle->estimate()->save($estimate);
         for ($i = 0; $i < count($input['item_id']); $i++) {
             $estimate_detail = new EstimateDetail();
             $estimate_detail->item_id = $input['item_id'][$i];
             $estimate_detail->item_description = $input['item_description'][$i];
             $estimate_detail->units = $input['units'][$i];
             $estimate_detail->rate = $input['rate'][$i];
             $estimate_detail->initial_amount = $input['amount'][$i];
             $estimate->estimate_details()->save($estimate_detail);
         }
         /*foreach ($estimate_detail as $item_row) {
               $estimate->estimate_details()->save($item_row);
           }*/
         //$estimate->estimate_details()->save($estimate_detail);
         //var_dump($estimate_detail);die;
         /*
         
         foreach ($input['item_id'] as $item) {
         
             $estimate->items()->save(new Item($item));
         
         }
         */
         //$vehicle->estimate()->save($estimate);
     }
     return redirect('/estimates');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $user = new User($request->only(['name', 'username', 'email', 'mobile_number', 'organisation', 'operation_areas', 'confirmed']));
     $user->password = bcrypt($request->password);
     $user->confirmation_code = str_random(32);
     $user->save();
     $vehicle = new Vehicle($request->only(['title', 'type', 'sat_number', 'name']));
     $vehicle->user_id = $user->id;
     $vehicle->save();
 }