PHP code example of zhuud / laravel-route-proxy

1. Go to this page and download the library: Download zhuud/laravel-route-proxy library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zhuud / laravel-route-proxy example snippets


      use Symfony\Component\Debug\Exception\FatalErrorException;
     /**
       * Render an exception into an HTTP response.
       *
       * @param \Illuminate\Http\Request $request
       * @param Exception $exception
       * @return Exception|\Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
       */
      public function render($request, Exception $exception)
      {
          // api路由错误直接返回
          if ($request->is('api*')) {

              // 程序错误直接退出
              if ($exception instanceof FatalErrorException) {

                  return response()->json([
                      'code'      => $exception->getCode()    ?? 1000000,
                      'message'   => $exception->getMessage() ?? 'Exception Unknown.',
                  ]);
              }

              return  $exception;
          }

          return parent::render($request, $exception);
      }
  

     /**
       * @param \Illuminate\Http\Request $request
       * @param \Illuminate\Support\Facades\Route $route
       * @return mixed
       */
      public function index(Request $request, Route $route)
      {
          return RouteProxy::parse()
          ->setMaxCalls(8)
          ->verMaxCalls($request)
          ->dispatch($request,$route::getRoutes())
          ->getResult();
      }