Support the ongoing development of Laravel.io →
IOC Packages
Last updated 2 years ago.
0
Solution

You're right, you don't need to put anything in the provides() method since you aren't binding anything with register().

I believe provides() is only used for deferred service providers, i.e. service providers that don't get run when the framework boots, but when a service they provide is requested from the IoC container. When Laravel compiles, it checks what services each deferred service provider provides, caches that in the storage/meta/services.json file which can then be looked up to find out which service provider class to execute to get the requested binding registered.

Last updated 2 years ago.
0

I've been reading around and I thought it would be something like this.

There are various tutorials on creating a Laravel's package, but none of them talks about the purpose of the provides() method. It's clearer to me now.

Thanks maknz!

Last updated 2 years ago.
0

Its clearly describe the purpose of provides method in ServiceProvider class.

please have a look to https://laravel.com/docs/5.4/providers#deferred-providers

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.