EDIT: I updated with probably what you want at the very end.
@timdr Ok, so normal assumption would be that routes.php when finds a match stops and sends the response.
But, instead it goes through all the registered route files, so, you don't need the middleware like approach.
So, first you might want to register new route to the boot method of RouteServiceProvider:
$this->routes(function () {
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/routes.php'));
//......
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/url_modifier.php')); // This new route handler
});
Then, in the url_modifier.php file, you can register custom routes overriding the route names from routes.php. There, you can either get custom routes from database, or manually. Here is what I tested:
// /routes/url_modifier.php
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
$runme = function () {
Route::get('/test', function () {
return "Overridden Content";
})->name("test");
};
$runme();
The route name test from routes.php is overridden properly, with this new route.
I would also suggest, to run artisan route:cache every time when admin makes changes to the custom routes. (using the Artisan Facade programmatically)
Note: The setUri function that you tried probably won't register permanently. While, with this way you have to re-assign the controller actions. I could not find any better solution yet.
Update:
This is probably what you exactly want. In the url_modifier.php use this:
$all_routes = collect(Route::getRoutes()->get());
$test = $all_routes->first(function ($value, $key) {
return isset($value->action['as']) && $value->action['as'] === "test"; // The route name
});
$test->setUri("something-else"); // Re-set the URL to custom
Again, make sure to run route:cache so that this overhead does not slow down the application.