0

I have not done much work with route service providers and there seems to have been some changes around Laravel 5.4.

Basically I wish to use the boot function in route service provider to retrieve the sub domain so I can then query the main database to then set the sub database config and reconnection. I understand this could be done through middleware, however wish to do it through service providers.

Route

    Route::group(['domain' => '{account}.prop.dev'], function() {
  Route::get('/login', function () {
      return 'login';
  });
});

I cant see any problems with the above and where I dump in the route service provider it dumps but if I make a function the function doesnt seem to run and I have not managed to retrieve the subdomain.

There seems to be a lot of information using

$router->

but have struggled to find information using

Route::

My route service provider attempt is as follows:

public function boot()
{

parent::boot();

  Route::pattern('domain', '[a-z0-9.]+');

    Route::bind('domain', function ($value) {
        $domain= Customer::whereSubdomain($value)->first();
        if ($domain) {

            return $domain;
        }
        throw new Exception('error message');
    });

}

Any help would be great.

James Parsons
  • 895
  • 5
  • 18
  • 36

1 Answers1

0

You can retrieve the domain using

request()->route()->parameter('domain');
Ben Swinburne
  • 25,669
  • 10
  • 69
  • 108
  • I dont think there is a request passed to the service provider? – James Parsons Oct 26 '17 at 12:17
  • The request helper grabs the current request wherever you are (except possibly a provider::register method). You can also grab it from `$this->app->request->route()->parameter('domain') in the provider i believe. – Ben Swinburne Oct 26 '17 at 12:19