Moving routes inside plugin break the app

Hi, i'm experiencing a strange behaviour in my app i have one custom plugin for the news mgmt i moved my routes from the app to the plugin
1 Reply
Soundmit
SoundmitOP5mo ago
Route::get('/news', [CategoryController::class, 'index'])->name('news.index'); //Tutte le news

Route::get('/news/{slug?}', [NewsController::class, 'show'])->name('news.show'); //Singola news

Route::get('/news/c/{slug?}', [CategoryController::class, 'index'])->name('category.index'); //News per categoria
Route::get('/news', [CategoryController::class, 'index'])->name('news.index'); //Tutte le news

Route::get('/news/{slug?}', [NewsController::class, 'show'])->name('news.show'); //Singola news

Route::get('/news/c/{slug?}', [CategoryController::class, 'index'])->name('category.index'); //News per categoria
as is, without modification but i get an error not present before i have a LocaleMenu controller in the app that serves for the menu translations

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Detit\Polipages\Models\Page;
use Illuminate\Support\Facades\View;
use RyanChandler\FilamentNavigation\Models\Navigation;

class LocaleMenu
{
public function handle(Request $request, Closure $next)
{
dd('LocaleMenu');
$locale = app()->getLocale();
$mainMenuHandle = "main-menu-{$locale}";
$footerMenuHandle = "footer-menu-{$locale}";

// $mainMenuItems = $this->getLocalizedMenuItems($mainMenuHandle, $locale);
$mainMenuItems = Navigation::fromHandle($mainMenuHandle);
View::share('mainMenuItems', $mainMenuItems);

// $footerMenuItems = $this->getLocalizedMenuItems($footerMenuHandle, $locale);
$footerMenuItems = Navigation::fromHandle($footerMenuHandle);
View::share('footerMenuItems', $footerMenuItems);

return $next($request);
}
}

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Detit\Polipages\Models\Page;
use Illuminate\Support\Facades\View;
use RyanChandler\FilamentNavigation\Models\Navigation;

class LocaleMenu
{
public function handle(Request $request, Closure $next)
{
dd('LocaleMenu');
$locale = app()->getLocale();
$mainMenuHandle = "main-menu-{$locale}";
$footerMenuHandle = "footer-menu-{$locale}";

// $mainMenuItems = $this->getLocalizedMenuItems($mainMenuHandle, $locale);
$mainMenuItems = Navigation::fromHandle($mainMenuHandle);
View::share('mainMenuItems', $mainMenuItems);

// $footerMenuItems = $this->getLocalizedMenuItems($footerMenuHandle, $locale);
$footerMenuItems = Navigation::fromHandle($footerMenuHandle);
View::share('footerMenuItems', $footerMenuItems);

return $next($request);
}
}
as you can see, this controller sets a pair of variable that i use in my view but, after moving the news route, i get Undefined variable $mainMenuItems because the localeMenu is not loaded at all this controller is registered in bootstrap/app

->withMiddleware(function (Middleware $middleware) {
$middleware->web(append:[
\App\Http\Middleware\LocaleMiddleware::class,
\App\Http\Middleware\LocaleMenu::class,
]);

})

->withMiddleware(function (Middleware $middleware) {
$middleware->web(append:[
\App\Http\Middleware\LocaleMiddleware::class,
\App\Http\Middleware\LocaleMenu::class,
]);

})
all the cache are cleared if i put back the rout in the main web.php all works fine, plugin routes/web.php also work beacause i can put a debug here after some researche, middleware are applied only if the routes are defined in the main route. to solve this i opted for a php code in the layout
Want results from more Discord servers?
Add your server