I am new to Laravel and didn't understand why service providers are there in Laravel. Why we use service provider and when to use.
Asked
Active
Viewed 2,419 times
7
-
2Did you read the [docs](https://laravel.com/docs/5.3/providers) – tam5 Oct 14 '16 at 10:24
-
Yes, I have gone through the docs but found high level things not in detail. – Naresh Ramoliya Oct 14 '16 at 10:26
-
@Naresh: hii...just go through this link `https://laraveltips.wordpress.com/2015/06/11/how-to-create-a-service-provider-in-laravel-5-1/`. May be it helps you!! – Hiren Gohel Oct 14 '16 at 10:31
-
2Ok. Basically, the service providers that you register will run when the application is instantiated (before any of your controllers or logic is called). This would be a good place to boot up or prepare any "services" or things that you want to have available in your code. For example, you may have a ViewServiceProvider which shares some data with every single view of the app. Does that help? – tam5 Oct 14 '16 at 10:31
-
@Hiren - link not working gives me - Oops! That page can’t be found. – Naresh Ramoliya Oct 14 '16 at 10:34
-
@tam --- little – Naresh Ramoliya Oct 14 '16 at 10:36
-
One of the keys to building a well architected Laravel application is learning to use serviceproviders as an organizational tool. When you are registering many classes with the IoC container, all of those bindings can start to clutter your app/start files. Instead of doing container registrations in those files, create serviceproviders that register related services. – Anand Mishra Oct 14 '16 at 10:37
-
1Follow the link:: well explained http://stackoverflow.com/questions/20439583/laravel-4-when-to-use-service-providers – Anand Mishra Oct 14 '16 at 10:38
-
Ok...so sorry...here it is:) https://laraveltips.wordpress.com/2015/06/11/how-to-create-a-service-provider-in-laravel-5-1/ – Hiren Gohel Oct 14 '16 at 10:40
1 Answers
-5
The service providers are the main part of the Laravel application/framework. So we can say that service providers are central element of the initialization process where all the relevant and required code is loaded by PHP.
You can find more about laravel service provider at laravel documentation.
Further you can read more about service provider with example.
Hope you get hint about service provider in laravel.

AddWeb Solution Pvt Ltd
- 21,025
- 5
- 26
- 57