Creating multiple Laravel sites using only one Laravel codebase
gizburdt released a cool Laravel package called Laravel Multisite. With this Laravel package, we can build multiple sites/sub-domains on one codebase.
Example:
Route::group([
'domain' => 'blog.'.config('multisite.host'),
'as' => 'blog.',
'middleware' => 'site:blog'
], function () {
Route::get('/', 'BlogController@homepage')->name('homepage');
});
The magic happens with the site middleware site:blog. This will tell your app that the routes within the group are belonging to the blog. It will provide a variable called $currentSite in all your views. There is also a config available, which you can access with Config::get('multisite.site').
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.3 Laravel 5.4 Laravel 5.2 Laravel 5.1 Advanced