/**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(CreateVehicleRequest $request, $makerId, $vehicleId)
 {
     //Verifying maker exist :
     $maker = Maker::find($makerId);
     if (!$maker) {
         return response()->json(['message' => 'This maker does not exist', 'code' => 404], 404);
     }
     //Comprobamos si existe el vehiculo
     $vehicle = $maker->vehicles->find($vehicleId);
     if (!$vehicle) {
         return response()->json(['message' => 'This vehicle does not exist', 'code' => 404], 404);
     }
     //Recuperamos el color
     $color = $request->get('color');
     //Recuperamos el power
     $power = $request->get('power');
     //Recuperamos capacity
     $capacity = $request->get('capacity');
     //Recuperamos speed
     $speed = $request->get('speed');
     $vehicle->color = $color;
     $vehicle->power = $power;
     $vehicle->capacity = $capacity;
     $vehicle->speed = $speed;
     $vehicle->save();
     return response()->json(['message' => 'The vehicle has been updated'], 200);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(CreateVehicleRequest $request, $makerId, $vehicleId)
 {
     $maker = Maker::find($makerId);
     if (!$maker) {
         return response()->json(['message' => 'This maker does not exist', 'code' => 404], 404);
     }
     $vehicle = $maker->vehicles->find($vehicleId);
     if (!$vehicle) {
         return response()->json(['message' => 'This vehicle does not exist', 'code' => 404], 404);
     }
     $vehicle->color = $request->get('color');
     $vehicle->power = $request->get('power');
     $vehicle->capacity = $request->get('capacity');
     $vehicle->speed = $request->get('speed');
     $vehicle->save();
     return response()->json(['message' => 'The vehicle has been updated'], 200);
 }
Ejemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(CreateVehicleRequest $request, $MakerId, $VehicleId)
 {
     $maker = Maker::find($MakerId);
     if (!$maker) {
         return response()->json(['message' => 'No such Maker', 'code' => 404], 404);
     }
     $vehicle = $maker->vehicles->find($VehicleId);
     if (!$vehicle) {
         return response()->json(['message' => 'No such Vehicle', 'code' => 404], 404);
     }
     $vehicle->color = $request->get('color');
     $vehicle->speed = $request->get('speed');
     $vehicle->power = $request->get('power');
     $vehicle->capacity = $request->get('capacity');
     $vehicle->save();
     return response()->json(['message' => 'The update of vehicle for Maker was correctly dooded'], 201);
 }
 /**
  * Update specific vehicles related to particular car maker
  * @param CreateVehicleRequest $request
  * @param $makerId
  * @param $vehicleId
  * @return \Illuminate\Http\JsonResponse
  */
 public function update(CreateVehicleRequest $request, $makerId, $vehicleId)
 {
     $maker = Maker::find($makerId);
     //if maker id is not found, error is displayed
     if (!$maker) {
         return response()->json(['message' => 'This maker does not exist', 'code' => 404], 404);
     }
     $vehicle = $maker->vehicles->find($vehicleId);
     if (!$vehicle) {
         return response()->json(['message' => 'This vehicle does not exist for this maker', 'code' => 404], 404);
     }
     $color = $request->get('color');
     $power = $request->get('power');
     $capacity = $request->get('capacity');
     $speed = $request->get('speed');
     $vehicle->color = $color;
     $vehicle->power = $power;
     $vehicle->capacity = $capacity;
     $vehicle->speed = $speed;
     $vehicle->save();
     return response()->json(['message' => 'The maker has been updated'], 200);
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(CreateVehicleRequest $request, $makerId, $vehicleId)
 {
     $maker = Maker::find($makerId);
     if (!$maker) {
         return $this->responseNotFound('Maker does not exist.');
     }
     $vehicle = $maker->vehicles->find($vehicleId);
     if (!$vehicle) {
         return $this->responseNotFound('Vehicle does not exist.');
     }
     $vehicle->color = $request->get('color');
     $vehicle->capacity = $request->get('capacity');
     $vehicle->power = $request->get('power');
     $vehicle->speed = $request->get('speed');
     $vehicle->save();
     return $this->responseUpdated('Vehicle was updated successfully.');
 }