예제 #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     for ($i = 0; $i < 30; $i++) {
         Vehicle::create(['color' => $faker->safeColorName(), 'power' => $faker->randomNumber(), 'capacity' => $faker->randomFloat(), 'speed' => $faker->randomFloat(), 'maker_id' => $faker->numberBetween(1, 5)]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $rules = array('plate_number' => 'required|unique:vehicles', 'vehicle_type_id' => 'required', 'license_type_id' => 'required');
     $messages = ['plate_number.required' => trans('vehicle.plate_number_error_message'), 'vehicle_type_id.required' => trans('vehicle.vehicle_type_error_message'), 'license_type_id.required' => trans('vehicle.license_type_error_message')];
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator)->withInput();
     }
     $license_types = $request->license_type_id;
     if (empty($license_types[0])) {
         return redirect()->back()->with('error', 'Atleast select one license type');
     }
     $model = Vehicle::create($request->all());
     foreach ($license_types as $license_type) {
         $model1 = new LicenseTypeVehicle();
         $model1->license_type_id = $license_type;
         $model1->vehicle_id = $model->id;
         $model1->save();
     }
     Session::flash('flash_message', trans('vehicle.vehicle_on_create'));
     return Redirect::to('/vehicles');
 }
예제 #3
0
 /**
  * Post the add vehicle form.
  *
  * @return Response
  */
 public function postAddVehicle(Request $request)
 {
     //validation
     $v = Validator::make($request->all(), ['reg_no' => 'required|min:2|max:15', 'make' => 'required|max:25', 'model' => 'required|max:25', 'transmission' => 'required|in:Automatic,Manual']);
     //Checking validation outcome
     if ($v->fails()) {
         /**
          * Validation failed
          * Redirecting back to the page with errors and inputs
          */
         return back()->withErrors($v)->withInput();
     } else {
         /**
          * Validation passed
          * Creating the vehicle record
          */
         $vehicle = Vehicle::create(['instructor_id' => $request->user()->instructor->instructor_id, 'reg_no' => $request->reg_no, 'make' => $request->make, 'model' => $request->model, 'transmission' => $request->transmission]);
         if ($vehicle) {
             return redirect()->action('InstructorController@getIndex')->with('message', 'Vehicle added!')->with('alert-class', 'alert-info');
         } else {
             return redirect()->action('InstructorController@getIndex')->with('message', 'Unable to add vehicle')->with('alert-class', 'alert-danger');
         }
         //End of if statement
     }
     //End of if statement
 }
예제 #4
0
 /**
  * Function that creates a vehicle.
  *
  * @return Response
  */
 public function createVehicle()
 {
     // Validate Input.
     $validator = Validator::make(Input::all(), array('formData' => 'required'));
     if ($validator->fails()) {
         return response()->json(['error' => 'Informacion incompleta!']);
     }
     // Check that user is part of authorized staff.
     if (Auth::user()->Type != 1) {
         // If they are unauthorized no point in returning anything.
         return response()->json(array());
     }
     // Get user branch.
     $branchId = Worker::find(Auth::user()->TypeId)->BranchId;
     // Make vehicle.
     $vehicle = Vehicle::create(array('BranchId' => $branchId, 'Model' => Input::get('formData')['vcModel'], 'Brand' => Input::get('formData')['vcBrand'], 'Efficiency' => Input::get('formData')['vcEfficiency'], 'Repair' => false, 'Type' => Input::get('formData')['vcType'], 'Value' => Input::get('formData')['vcValue'], 'Depreciation' => Input::get('formData')['vcDepreciation'], 'Latitude' => Input::get('formData')['vcLatitude'], 'Longitude' => Input::get('formData')['vcLongitude'], 'PlateNumber' => Input::get('formData')['vcPlate']));
     $response['state'] = 'Success';
     $response['vehicle'] = $vehicle;
     $response['message'] = 'Vehiculo creado exitosamente!';
     return response()->json($response);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(VehicleRequest $request)
 {
     Vehicle::create($request->all());
     Session::flash('flash_message', 'Vehicle added!');
     return redirect('camp/vehicles');
 }