问题
Is there a way to register a service provider in Laravel just for certain routes/URLs? I would like to know if it's possible to bind a service only where you need it and if it helps reduce the strain while booting.
回答1:
I'm not sure that it's possible to register a service provider only on particular routes, however you could defer it. Just set
protected $defer = true;
on your service provider then this will only be resolved when needed which should improve performance depending on your particular use case.
For more check out the official docs on this here but it might just be what you need.
来源:https://stackoverflow.com/questions/36620964/binding-a-laravel-service-provider-on-specific-routes