From 2391c9d27e7c5f9e5816f28e7c174f6759b3450f Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 1 Oct 2024 14:59:13 +0100 Subject: [PATCH] Autoload addon routes --- src/Providers/AddonServiceProvider.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/Providers/AddonServiceProvider.php b/src/Providers/AddonServiceProvider.php index f1a78c7717..dd18ef52dc 100644 --- a/src/Providers/AddonServiceProvider.php +++ b/src/Providers/AddonServiceProvider.php @@ -463,15 +463,35 @@ protected function bootPublishables() protected function bootRoutes() { - if ($web = Arr::get($this->routes, 'web')) { + $directory = $this->getAddon()->directory(); + + $web = Arr::get( + array: $this->routes, + key: 'web', + default: $this->app['files']->exists($path = $directory.'routes/web.php') ? $path : null + ); + + if ($web) { $this->registerWebRoutes($web); } - if ($cp = Arr::get($this->routes, 'cp')) { + $cp = Arr::get( + array: $this->routes, + key: 'cp', + default: $this->app['files']->exists($path = $directory.'routes/cp.php') ? $path : null + ); + + if ($cp) { $this->registerCpRoutes($cp); } - if ($actions = Arr::get($this->routes, 'actions')) { + $actions = Arr::get( + array: $this->routes, + key: 'actions', + default: $this->app['files']->exists($path = $directory.'routes/actions.php') ? $path : null + ); + + if ($actions) { $this->registerActionRoutes($actions); }