From ca03cebd93f219409890cc3ad0d81bcaeb8b51b7 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 1 Oct 2024 15:43:30 +0100 Subject: [PATCH] [5.x] Auto-load addon routes (#10880) --- 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 21ac34c801..9fba9bae33 100644 --- a/src/Providers/AddonServiceProvider.php +++ b/src/Providers/AddonServiceProvider.php @@ -467,15 +467,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); }