picked laravel 5.2 time ago have never had use subdomains before.
at moment have:
route::group(['middleware' => ['web']], function () { //login/logout route::get('/', 'auth\authcontroller@getlogin'); route::get('/auth/login', 'auth\authcontroller@getlogin'); route::post('/auth/login', 'auth\authcontroller@postlogin'); route::get('/logout', 'auth\authcontroller@logout'); });
the thing is, if want grab subdomain (if 1 exists), don't know how pass '/'
route within middleware group well. lot of subdomain routing tutorials don't seem include/reference middleware web (as have forms on page , need functionality also).
route::group(['middleware' => ['web']], function () { //login/logout route::get('/', 'auth\authcontroller@getlogin'); route::get('/auth/login', 'auth\authcontroller@getlogin'); route::post('/auth/login', 'auth\authcontroller@postlogin'); route::get('/logout', 'auth\authcontroller@logout'); }); route::group(['domain' => '{account}.myapp.com'], function () { route::get('/}', function ($account) { //doesn't work }); });
doesn't work. want subdomain (if exists), , stick in through can recall in login view.
here approach use. wrap routes inside web
middleware, , wrap other routes, exception of public pages home
, about
, etc, in auth
middleware. there, can grab variable subdomains last, after constant subdomains (if applicable).
// encapsulate routes web middleware route::group(['middleware' => 'web'], function () { // include auth routes route::auth(); // these routes require user logged in route::group(['middleware' => 'auth'], function () { // constant subdomain route::group(['domain' => 'admin.myapp.localhost.com'], function () { // admin stuff }); // variable subdomains route::group(['domain' => '{account}.myapp.localhost.com'], function () { // homepage of variable subdomain route::get('/', function($account) { // return {account}, can pass along you'd return $account; }); }); }); // public homepage route::get('/', function () { // homepage stuff }); });
it works setup hope helps towards solution.
Comments
Post a Comment