Binding a Laravel service provider on specific routes

情到浓时终转凉″ 提交于 2019-12-13 02:26:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!