Laravel is a powerful framework, and the Laravel request lifecycle is the best place to start when you want to learn more about the framework itself. An in-depth examination of the request lifecycle will aid our understanding of the Laravel structure.
- All requests into your application are directed from the user to Webserver through the
public/index.phpscript. When using Apache, the
.htaccessfile that ships with Laravel handles the passing of all requests to
- Then it retrieves an instance of the Laravel application from
bootstrap/app.phpscript. Laravel itself creates an instance of the application, which is the initial/first step.
- After that, The incoming request is sent to either the HTTP kernel or the console kernel, depending on the type of request that is entering the application . These two kernels serve as the central location that all requests flow through. HTTP kernel, which is placed in
app/Http/Kernel.php. It just receives a Request and returns a Response. Bootstrappers are defined by the Kernel class, which configures error handling, configures logging, detects environments and other tasks to be done before the request is handled. HTTP Kernel will define the list of middleware that is passed through before being handled by the application.
- The most important concept to grasp when learning about Laravel’s bootstrap process is Service Providers. You can find a list of service providers by opening your
app/config/app.phpconfiguration file and finding the
providersarray. These providers serve as the primary bootstrapping mechanism for Laravel. But, before we dig into service providers, let's go back to
index.php. After a request enters your
bootstrap/start.phpfile will be loaded. This file creates the new Laravel
Applicationobject, which also serves as an IoC container.
- Now request will be dispatched by the Router and it will end up with the views as shown below:
- Router will direct the HTTP Request to a Controller or return a view or responses directly by omitting the controller. These routes will be placed in
app/controllers/performs specific actions and sends data to a View.
app/views/formats the data appropriately, providing the HTTP Response.