Laravel 5.6 Routes with env variables

I’m working on a Laravel 5.6 project that has a dynamic route based on an environment variable that I’m also setting in the config (for easy access and to avoid the dot env issue).

The Laravel documentation was leading me down the wrong path with using the domain handler. Using that, the site kept redirecting me annoyingly to what looked like a very invalid IP. I managed to get it with prefix instead. Here’s my code:

Route::prefix(config('app.eventYear'))->name('year.')->group(function () {  
   Route::get('/', 'PageController@index')->name('index');
});

This way the url could be: test.com/2018 and will be easily updated by the env and not hardcoded.