- Folder Structure
- Code Samples
- Register Service Providers
- Information about Laravel Service Providers
Providers (are short names for Service Providers).
Providers are the central place of configuring and bootstrapping a Container.
They are the place where you register things like container bindings, event listeners, middleware, routes, other providers, aliases... to the framework service container.
There are 2 types of Providers in a Container, the Main Provider and the Additional (Job Specific) Providers (EventsProvider, BroadcastsProvider, AuthProvider, MiddlewareProvider, RoutesProvider).
A Container MAY have one or many Providers and MAY have no Provider at all.
A Container CAN have only a single Main Provider.
The Main Provider is where all the Job Specific Providers get registered.
Third party packages Providers MUST be registered inside the Container Main service provider. (Same applies to Aliases).
Providers CAN be registered on the Ship Main Provider, if they are general or are intended to be used by many containers. (Same applies to Aliases).
The Main Provider will be auto registered by the Ship Engine, so no need to register it manually anywhere.
All Main Providers MUST extend from
All other types of Providers (EventsProvider, BroadcastsProvider, AuthProvider, MiddlewareProvider, RoutesProvider) must extend from their parent providers
The Main Provider MUST be named
MainServiceProviderin every container.
You should not register any Provider in the framework (
Example: User Container
In this example above only the
EventsServiceProvider needs to be registered in
MainServiceProvider. While the
MainServiceProvider will get automatically registered.
No need to register the
MainService Provider anywhere, it will be automatically registered, and it is responsible for registering all Container Additional (Job Specific) Providers.
You MAY add as many Additional Service Providers as you want in a Container. However, in order to get them loaded in the framework you MUST register them all in the
MainService Provider as follows:
Same rule applies to Aliases.
If a package requires registering its service provider in the
config/app.php, you SHOULD register its service provider in the Main container where you are using it.
However, if it's a generic package used by the entire framework and not a specific Container or feature. Then you can register that service provider in the
app/Ship/Providers/ShipProvider.php, but never in the
By default, Laravel provides some service providers in its
In apiato those providers have been renamed and moved to the Ship Layer
You should not touch those providers, instead you have to extend them from a containers providers in order to modify them. Example: the app/Containers/AppSection/Authentication/Providers/AuthProvider.php is extending the AuthServiceProvider to modify it.
Those providers are not auto registered by default, thus writing any code there will not be available, unless you extend them. Once extended the child Provider should be registered in its Container Main Provider, which makes its parent available.
This rule does not apply to the
RouteServiceProvider since it's required by Apiato, this Provider is registered by the
More info at Laravel Docs.