With processing in the middleware I mean the following. To avoid running each module on say /module1 /module2 and need an awareness of "subdomains" I wanted to include module specific routes with its own namespace. So based on context based on a routing table someurl routes to module 1 on / and anotherurl routes to module 2 on /.
What I wanted is to take the routing table array and check if the user has changed the module context, so the same url should route to another module. To make that work I have to create a session to say something like module_context = routeID that will override the database for that session only.
The problem with the request is you can access the session while being in middleware, but when accessing the request in the group (where I include the context routes) the request loose the sessions (all sessions including the laravel ones). I passed the routing array via a use statement on the function, but that doesnt solve my problem I need to check for the context
Here is an example of how I route is with a cookie, but I wanted to use a session instead
//Checking if we have set a context override
if (Request::hasCookie('module_context'))
{
$context = Crypt::decrypt(Request::cookie()['module_context']);
}
else
$context = null;
//dd(Crypt::decrypt(Request::cookie()['test']));
$path = app_path('Http/Routes');
use App\Models\DomainRoute;
//Default Routes Should Always Run
$loadRoutes = array('Shared',
'Default',
'Administration',
'User');
$router = new DomainRoute();
$newRoute = $router->getRoute(Request::getHost(), $context);
//Add the route if it exist
if ($Addroute = addRoute($newRoute, $loadRoutes))
$loadRoutes[] = $Addroute;
function addRoute($route, $routes)
{
if (!in_array($route, $routes))
return $route;
else return false;
}
//Standard group at lowest level to take care of localization
Route::group(['middleware' => ['cors'], 'prefix' => LaravelLocalization::setLocale()],
function() use ($loadRoutes)
{
// Dynamically include the needed routes
foreach ($loadRoutes as $file)
{
if (file_exists(__DIR__.'/routes/'.$file.'.php'))
{
require_once (__DIR__.'/routes/'.$file.'.php');
}
}
});