public function insert_vehicles(Request $request) { $vehicle = new Vehicle(); $vehicle->vehicle_model = $request->input('model'); $vehicle->vehicle_number = $request->input('vehi_num'); $vehicle->vehicle_type = $request->input('type'); $vehicle->remarks = $request->input('remarks'); $vehicle->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), Vehicle::$rules, Vehicle::$messages); if ($validator->passes()) { $vehicle = new Vehicle(); $vehicle->chasis = Input::get('chasis'); $vehicle->enginecc = Input::get('enginecc'); $vehicle->engineno = Input::get('engineno'); $vehicle->yor = Input::get('yor'); $vehicle->destination = Input::get('destination'); $vehicle->make = Input::get('make'); $vehicle->model = Input::get('model'); $vehicle->location_id = Input::get('location_id'); $vehicle->vec = ''; $vehicle->inspection_date = Input::get('inspection_date'); $vehicle->charge = Location::find(Input::get('location_id'))->location_charge; $vehicle->user_id = Auth::id(); $vehicle->save(); $file = Input::file('vec'); $extension = $file->getClientOriginalExtension(); $fileName = "VEC" . $vehicle->id . '.' . $extension; $vehicle->vec = $fileName; $vehicle->save(); $file->move('uploads', $fileName); //Upload the file to public/uploads // CREATE NEW VEHICLE INSPECTION RECORD $insp = new VehicleInspection(); $insp->vehicle_id = $vehicle->id; $insp->save(); //CREATE NEW VEHICLE ROADWORTHINESS RECORD $insp_details = new InspectorDetails(); $insp_details->vehicle_id = $vehicle->id; $insp_details->save(); //Event::fire('vehicle.create', [$vehicle]); return Redirect::to('vehicles')->with('success', 'Vehicle Added Successfully'); } else { return Redirect::to('vehicles/create')->withErrors($validator)->withInput(); } }
/** Creates a new model. If creation is successful, the browser will be redirected to the 'show' page. */ public function actionCreate() { $model = new Vehicle(); if (isset($_POST['Vehicle'])) { // Submit $model->attributes = $_POST['Vehicle']; // Additional attributes // mmmm.. no me gusta mucho a nivel de seguridad // y encima tengo que meter un hidden en el form para que lo devuelva!!! //!!!! // paliado chequeando que sea un admin al menos if (!empty($_POST['uid']) && Yii::app()->user->checkAccess('adminVehicles')) { // Submit // Force uid by an admin $model->uid = $_REQUEST['uid']; Yii::app()->user->setState('userMarked', $_REQUEST['uid']); } else { $model->uid = Yii::app()->user->id ? Yii::app()->user->id : 0; } $model->created = time(); $model->changed = time(); // Save time if ($model->save()) { Flashes::addInfoFlash(Yii::t('amo', 'Vehicle created successfully')); if ($_REQUEST['submitAndNew']) { $this->refresh(); } else { $this->redirect(array('show', 'id' => $model->vid)); } } else { Flashes::addErrorFlash(Yii::t('amo', 'Could not create vehicle.') . ' ' . Yii::t('amo', 'Please, try again later.')); } } // RENDER THE FORM: Send uid and username $uidMarked = Yii::app()->user->getState('userMarked'); if (!empty($uidMarked)) { $user = User::model()->findbyPk($uidMarked); } $this->render('create', array('model' => $model, 'uid' => $uidMarked, 'username' => $user->name)); }
$data_compra->setRestriccio(true); $combustible = $form->crearElement("combustible"); $combustible->setTipus("seleccio", array('Electric', 'Diesel', 'Gasolina')); $combustible->setRestriccio(true); $asseguranca = $form->crearElement("asseguranca"); $asseguranca->setTipus("numeric"); $asseguranca->setRestriccio(false); include 'classes/Llistes/LlistaModels.php'; $models = new LlistaModels(); if (count($_POST)) { if ($form->valida($_POST)) { $infos = array(); array_push($infos, $matricula, $model, $color, $data_compra, $combustible, $asseguranca); $vehicle = new Vehicle(); $vehicle->setInfos($infos); if ($vehicle->save()) { header('location: afegir_vehicle.php?inserit=' . $matricula->getValor()); exit; } else { $errors = $vehicle->getErrors(); echo "ups"; } } else { $errors = $form->mostrarErrors(); } } else { $errors = $form->mostrarErrors(); } ?>