Example #1
0
 /**
  * Store Detail vehicle
  *
  * @param Request      $request
  * @param Model|Header $header
  * @param bool         $coverage
  *
  * @return bool
  */
 public function storeVehicle($request, $header, $coverage = false)
 {
     $this->data = $request->all();
     try {
         if ($this->data['year'] === 'old') {
             $this->data['year'] = $this->data['year_old'];
         }
         $id = date('U');
         $detail = ['id' => $id, 'ad_vehicle_type_id' => $this->data['vehicle_type']['id'], 'ad_vehicle_make_id' => $this->data['vehicle_make']['id'], 'ad_vehicle_model_id' => $this->data['vehicle_model']['id'], 'ad_retailer_product_category_id' => $this->data['category']['id'], 'year' => $this->data['year'], 'license_plate' => $this->data['license_plate'], 'use' => $this->data['use'], 'mileage' => (bool) $this->data['mileage'], 'insured_value' => $this->data['insured_value']];
         if ($coverage) {
             $detail['color'] = $this->data['color'];
             $detail['engine'] = $this->data['engine'];
             $detail['chassis'] = $this->data['chassis'];
             $detail['tonnage_capacity'] = $this->data['tonnage_capacity'];
             $detail['seat_number'] = $this->data['seat_number'];
         }
         $header->details()->create($detail);
         if ($coverage && $this->getDetailById($id)) {
             return true;
         }
         return true;
     } catch (QueryException $e) {
         $this->errors = $e->getMessage();
     }
     return false;
 }