On Service Providers and Laravel's life cycle
In this blog post I talk about Laravel's Service Providers and about its life cycles.
In brief, a Laravel application is bootstrapped (started) whenever a webrequest hits
index.php in the
public folder, or when an
artisan command is executed. Tough both the
artisan file work very similarly, I will only talk about
index.php file is called it registers the autoloader. After that Laravel's Application is initiated and stored in the
$app variable which is used to construct a kernel that manages the input and output of our app.
After handling the input by our
$kernel it returns a
$response object which is send back to our visitor.
Let's rewind a bit, there are four1 important things that are done in the
- The autoloader is registered
Applicationclass is initiated and stored in
- A kernel is constructed using the
$app's Service Container.
- The kernel handles our input and returns a response.
The goal of this blog post is to explain the inner workings of Laravel's life cycle. The next section describes how the
Applicaiton class works
Laravel's Application object
When a Laravel application is bootstrapped a
Applicaiton object is made in
bootstrap/app.php. This object can be found in
There are two important bits about this class: it extends the
Illuminate\Container\Container and implements a
So how do Service Providers work?
- Actually there is a fifth step where we terminate the kernel which will call the
terminatemethod on any active
TerminableMiddlewareand terminates the