How to use the laravel subdomain routing function

I am using the following code: its from laravel 4 site

Route::group(array('domain' => '{account}.myapp.com'), function() { Route::get('user/{id}', function($account, $id) { // ... return Redirect::to('https://www.myapp.com'.'/'.$account); }); }); 

The idea is to redirect subdomain.myapp.com to myapp.com/user/subdomain. What I have is no suggestions working? Sorry, I just started with laravel for about a month.

+6
source share
3 answers

Remove user/{id} and replace it with / , and then use the following URL https://accountname.myapp.com and redirect it to https://www.myapp.com/accountname

 Route::group(array('domain' => '{account}.myapp.com'), function() { Route::get('/', function($account, $id) { // ... return Redirect::to('https://www.myapp.com'.'/'.$account); }); }); 

Edit the answer to the correct answer

+9
source
 Route::group(array('domain' => '{account}.myapp.com'), function() { Route::get('/', function($account) { // ... return Redirect::to('https://www.myapp.com/'.$account); }); }); 

since Marc vd M answers, but removes $ id from the close function of the close.

why use 'https://www.myapp.com'.'/'.$account , rather than 'https://www.myapp.com/'.$account

+2
source
 Route::group(['domain' => '{account}.myapp.com'], function () { Route::get('user/{id}', function ($account, $id) { // }); }); 

Source: https://laravel.com/docs/5.3/routing#route-group-sub-domain-routing

-3
source

All Articles