- Folder Structure
- Code Samples
- Register Service Providers:
- Laravel 5.5 Auto Discovery feature
- 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 (
config/app.php), only the
ApiatoProvidershould be registered there.
Important Information: Laravel 5.5 introduces an
auto-discoveryfeature that lets you automatically register
ServiceProviders. Due to the nature and structure of Apiato applications, this features is turned off, because it messes up how
configfiles are loaded in apiato. This means, that you still need to manually register 3rd-party
Example: User Container
In this example above only the
EventsServiceProvider needs to be registered in
UserServiceProvider. While the
UserServiceProvider will get automatically registered (since it's named based on his Container name).
Main Service Provider Example:
Note: when defining
boot() function in your Main provider "only" you must call the parent functions (
parent::boot()) from your extended function.
No need to register the Main
Service Provider anywhere, it will be automatically registered, and it is responsible for registering all the 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 Main
Service 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
This feature is disabled in Apiato so far. More details here.
By default, Laravel provides some service providers in its
In apiato those providers have been renamed and moved to the Ship Layer
VIP Note: you should not touch those providers, instead you have to extend them from a containers providers in order to modify them.
app/Containers/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