Ejemplo n.º 1
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     /*
      * Notification on TokenMismatchException
      */
     if ($e instanceof TokenMismatchException) {
         Notification::error(trans('global.Security token expired. Please, repeat your request.'));
         return redirect()->back()->withInput();
     }
     if ($e instanceof HttpResponseException) {
         return $e->getResponse();
     } elseif ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     } elseif ($e instanceof AuthorizationException) {
         $e = new HttpException(403, $e->getMessage());
     } elseif ($e instanceof ValidationException && $e->getResponse()) {
         return $e->getResponse();
     }
     if ($this->isHttpException($e)) {
         return $this->toIlluminateResponse($this->renderHttpException($e), $e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             return response()->view('errors.500', [], 500);
         }
         return $this->toIlluminateResponse($this->convertExceptionToResponse($e), $e);
     }
 }
Ejemplo n.º 2
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Exception               $e
  *
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     /*
      * Error 404 when a model is not found
      */
     if ($e instanceof ModelNotFoundException) {
         return response()->view('errors.404', [], 404);
     }
     /*
      * Notification on TokenMismatchException
      */
     if ($e instanceof TokenMismatchException) {
         Notification::error(trans('global.Security token expired. Please, repeat your request.'));
         return redirect()->back()->withInput();
     }
     if ($this->isHttpException($e)) {
         return $this->toIlluminateResponse($this->renderHttpException($e), $e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             return response()->view('errors.500', [], 500);
         }
         return $this->toIlluminateResponse((new SymfonyDisplayer(config('app.debug')))->createResponse($e), $e);
     }
 }
Ejemplo n.º 3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $route = Route::find($id);
     if ($route->validate(Input::all(), Route::$rules)) {
         if (Input::get('origin_location_id') == $route->origin_location_id && Input::get('destination_location_id') == $route->destination_location_id) {
             if (Input::get('distance') == $route->distance) {
                 return redirect('routes');
             } else {
                 $route->distance = Input::get('distance');
                 $route->save();
                 Notification::success('Ruta #' . $route->id . ' editada correctamente');
                 return redirect('routes');
             }
         } else {
             $origin_on_db = Route::where('origin_location_id', '=', Input::get('origin_location_id'))->where('destination_location_id', '=', Input::get('destination_location_id'))->first() !== null;
             if (!$origin_on_db) {
                 $route->update(Input::except('_token'));
                 Notification::success('Ruta #' . $route->id . ' editada correctamente');
                 return redirect('routes');
             } else {
                 Notification::error('La ruta ya se encuentra registrada en el sistema');
                 return redirect()->back()->withInput();
             }
         }
     } else {
         $errors = $route->errors();
         return redirect()->back()->withInput()->withErrors($errors);
     }
 }