Tuesday, April 11, 2017

Laravel using subdomain as parameter in route

I have an Laravel application that can be accessed by multiple subdomains, so I configured a route group for this and inside that route group I've created a route to access one of my controllers. The route is as follows:

    Route::group(['domain' => '{account}.domain.com'], function() {
        Route::get('foobar/{param}', 'MyController@foobar');
    })

MyController@foobar is like this

        public function foobar($param) {
            return $param;
        }

When I make a request to 'mysub.domain.com/foobar/sometext' I expected the value of $param to be 'sometext' but it's actually 'mysub' from the subdomain.

If change the route and the controller to expect more parameters the first parameter is always the subdomain.

How can I make the controller stop receving the subdomain as the first param and just receive 'sometext'?



via Lucas Marçal Dos Santos

Advertisement