Reputation: 667
I am using wildcard subdomains and want to pass the $element
variable into the middleware whitelabel so I can check the subdomain and respond accordingly.
Route::group(['domain' => '{element}.website.co', 'middleware' => 'whitelabel'], function() {
Route::get('/', 'AuthController@getLogin');
Route::post('/', 'AuthController@postLogin');
});
How would I use the value of element within the middleware?
Upvotes: 1
Views: 308
Reputation: 35220
Firstly, (unless you already have done) you'll need to add the following to your:
Route::pattern('element', '[a-z0-9.]+');
You can add it to the boot()
method of your AppServiceProvider
.
Then to access it in your middleware you would have something like:
public function handle($request, Closure $next)
{
$domain = $request->route('element');
return $next($request);
}
Hope this helps!
Upvotes: 1