Laravel (5.7) Request Lifecycle
Introduction:
It's important to understand the inner workings of any tool you are given to work with, a complete understanding of that tool will enable you to use all the power that comes with the tool. In this case, understanding how laravel works under the hood will help us utilize all of it's awesome "power". When we want to learn more about the laravel framework, the request lifecycle is the best place to start. It defines what's happening between an http request to our application till the response. Looking at the request lifecycle in depth will help us understand laravel’s structure better.
Lifecycle Overview
Everything in a laravel application starts from the index.php file found in the public directory. The index.php file is so important because any call or request into our application will initially route to it. In the index.php file, the application gets stored as an application instance, which could also be called a service container. Behind the scenes, different things are happening in the service container. One of which is the registration and storage of core classes that can be used later.
HTTP Kernel
The HTTP Kernel is located in the app/Http/Kernel.php , all the application's middlewares are registered in this file such as the middleware groups and the route middlewares. The http kernel is the next place the incoming request is sent to. It receives a request and returns a response. All of this is accomplished by the handle method available to the Kernel class. Once the handle method recognises a HTTP request, it returns a HTTP response. The Kernel class extends the Illuminate\Foundation\Http\Kernel class which contains a bootstrap method. This method checks if our application has been bootstrapped already. If not, the bootstrap method runs on a bunch of classes to bootstrap the application. It loads the configuration file, loads also the environment variables, handles exceptions, registers facades and also registers the application’s service providers. The application's default service providers are stored in the app/Providers directory.
Previous:
Laravel (5.7) Deployment
Next:
Laravel (5.7) Service Container
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/laravel/request-lifecycle.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics