1

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?

1 Answer 1

1

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.