Laravel: Optional route prefix parameter

Viewed 2074

I'm currently working on a multi-site application (one codebase for multiple (sub)sites) and I would love to leverage route caching, but currently I'm hardcoding a prefix instead of dynamically determining it.

When trying to do this I'm running into an issue which I've illustrated below:

Route::group(['prefix' => '{subsite}', 'subdomain' => '{site}.domain.tld'], function () {
    Route::get('blog', 'BlogController@index')->name('blog.index');
});

When accessing a subsite like http://sitename.domain.tld/subsitename/blog this all works fine, but it doesn't work anymore when not accessing a subsite like http://sitename.domain.tld/blog, as it will now think that the prefix is 'blog'.

Is there any way to allow the 'subsite' parameter to be empty or skipped?

Thanks!

1 Answers
Related