Explorar o código

Class `Mpociot\ApiDoc\ApiDoc` returned

Andrey Helldar %!s(int64=5) %!d(string=hai) anos
pai
achega
1950638051
Modificáronse 3 ficheiros con 51 adicións e 2 borrados
  1. 8 0
      config/apidoc.php
  2. 36 0
      src/ApiDoc.php
  3. 7 2
      src/ApiDocGeneratorServiceProvider.php

+ 8 - 0
config/apidoc.php

@@ -55,6 +55,14 @@ return [
              */
 
             'laravel' => [
+                /*
+                 * Autoload routes for the app.
+                 *
+                 * Default, false.
+                 */
+
+                'autoload' => false,
+
                 /*
                  * URL prefix of routes for your documentation.
                  *

+ 36 - 0
src/ApiDoc.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Mpociot\ApiDoc;
+
+use Illuminate\Support\Facades\Route;
+
+class ApiDoc
+{
+    /**
+     * Binds the ApiDoc routes into the controller.
+     *
+     * @deprecated Use
+     *
+     * @param string $path
+     */
+    public static function routes($path = '/doc')
+    {
+        Route::prefix($path)
+            ->namespace('\Mpociot\ApiDoc\Http')
+            ->middleware(static::middleware())
+            ->group(function () {
+                Route::get('/', 'Controller@blade')->name('apidoc');
+                Route::get('.json', 'Controller@json')->name('apidoc.json');
+            });
+    }
+
+    /**
+     * Get the middlewares for Laravel routes.
+     *
+     * @return array
+     */
+    protected static function middleware()
+    {
+        return config('apidoc.routes.laravel.middleware', []);
+    }
+}

+ 7 - 2
src/ApiDocGeneratorServiceProvider.php

@@ -2,7 +2,6 @@
 
 namespace Mpociot\ApiDoc;
 
-use Illuminate\Support\Facades\Route;
 use Illuminate\Support\ServiceProvider;
 use Mpociot\ApiDoc\Commands\GenerateDocumentation;
 use Mpociot\ApiDoc\Commands\RebuildDocumentation;
@@ -48,9 +47,15 @@ class ApiDocGeneratorServiceProvider extends ServiceProvider
         //
     }
 
+    /**
+     * Initializing routes in the application.
+     */
     protected function bootRoutes()
     {
-        if (config('apidoc.type', 'static') == 'laravel' && ! Route::has('apidoc')) {
+        if (
+            config('apidoc.type', 'static') === 'laravel' &&
+            config('apidoc.routes.laravel.autoload', false)
+        ) {
             $this->loadRoutesFrom(
                 __DIR__ . '/../routes/laravel.php'
             );