예제 #1
0
 /**
  * Store a newly created resource in storage.
  * PUT /marks/{id}/models
  *
  * @param int $id
  * @return Response
  */
 public function store()
 {
     //        dd(Input::all());
     $mark = MarkRef::find(Input::get('mark'));
     if (!$mark) {
         return $this->respondNotFound('Mark not found');
     }
     $model = new ModelRef(Input::all());
     $model->vehicle_type_id = Input::get('vehicle_type');
     if ($model = $mark->models()->save($model)) {
         Generator::findOrCreate($mark->name . ' ' . $model->name, 'Все что касается этой модели');
         return Redirect::action('ModelRefsController@listAll');
     }
     return $this->respondServerError('Error saving model');
 }
예제 #2
0
 /**
  * Update the specified resource in storage.
  * PATCH /marks/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $mark = MarkRef::find($id);
     if (!$mark) {
         return $this->respondNotFound('Mark not found');
     }
     if (Input::has('vehicle_type')) {
         $mark->vehicleTypes()->detach();
         $mark->vehicleTypes()->attach(Input::get('vehicle_type'));
     }
     $mark->fill(Input::except('vehicle_type'));
     if ($mark->save()) {
         return Redirect::action('MarkRefsController@index');
     }
     return App::abort('Wrong params');
 }
예제 #3
0
 /**
  * Store a new car
  * POST /api/users/self/cars
  *
  * @return Response
  */
 public function selfStore()
 {
     $user = Auth::user();
     //		if (!Input::has('number'))
     //			return $this->respondInsufficientPrivileges('Please select number');
     $validator = Car::validate(Input::all());
     if ($validator->fails()) {
         return $this->respondInsufficientPrivileges($validator->messages()->all());
     }
     $number = strtoupper(Input::get('number'));
     //		if ($number[2] == 'Z' && $number[3] == 'Z')
     //			return $this->respondInsufficientPrivileges('Wrong number. There is no ZZ');
     $region = substr($number, 0, 2);
     if (is_numeric($number[0]) && (int) Input::get('vehicle_type') != 3) {
         // smells a bit but whatever
         switch ((int) $region) {
             case $region == 0:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 73 && $region <= 84:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 86 && $region <= 89:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
             case $region >= 91 && $region <= 98:
                 return $this->respondInsufficientPrivileges('Недопустимый код региона');
         }
     }
     if (is_numeric($number[0]) && strlen($number) > 6) {
         $zerosCount = 3;
         // amount of zeros
         // check if all numbers are zeros
         $zeros = array_diff(array_slice(str_split($number), 4), array_fill(0, $zerosCount, 0));
         if (empty($zeros)) {
             return $this->respondInsufficientPrivileges("Номер не может быть с {$zerosCount} нулями");
         }
     } elseif (strlen($number) > 6) {
         $zerosCount = 6;
         $zeros = array_diff(array_slice(str_split($number), 1), array_fill(0, $zerosCount, 0));
         if (empty($zeros)) {
             return $this->respondInsufficientPrivileges("Номер не может быть с {$zerosCount} нулями");
         }
     }
     // if seria in number are in AA, PA, РМ, YP. Which is not allowed.
     if (Car::checkSeria($number)) {
         return $this->respondInsufficientPrivileges('Номера с сериями АА, РА, РМ и YP добавляются в профиль пользователя службой поддержки только при подтверждении факта владения или пользования данной машиной. Обратитесь в техподдержку.');
     }
     $car = new Car(Input::all());
     $mark = MarkRef::find($car->mark);
     $model = ModelRef::find($car->model);
     $vehicleType = VehicleTypeRef::find($car->vehicle_type);
     $this->subscribe($user, "{$this->morphWord($vehicleType)} {$mark->name}");
     $this->subscribe($user, $mark->name . ' ' . $model->name);
     if ($user->cars()->save($car)) {
         $imgCollection = Image::findMany(Input::get('img'));
         foreach ($imgCollection as $imgObject) {
             $car->images()->save($imgObject);
         }
         return $this->respond($this->collectionTransformer->transformCar($car));
     }
     return $this->respondServerError();
 }