Access Request in Service Provider After Applying Middleware
In service provider
You can also access Request Object
by:
public function register()
{
$request = $this->app->request;
}
Try like this:
public function register()
{
$this->app->bind('MyInterface', function () {
$request = app(\Illuminate\Http\Request::class);
return app(MyImplementation::class, [$request->foo]);
}
}
Binding elements works like this that they will be triggered only when they are call.