When a user sends a request, it first reaches public/index.php, which starts Laravel. Then bootstrap/app.php loads the application. The HTTP Kernel receives the request and runs the middleware. After that, Laravel matches the request to a route, which calls the appropriate controller. The controller interacts with the model, the model accesses the database, and finally the controller returns a view or JSON response to the user.
1. public/index.php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';- Loads Composer's autoloader.
- Loads all installed packages.
- Creates the Laravel application.
2. bootstrap/app.php
This file creates the Laravel application.
$app = new Illuminate\Foundation\Application(
$_ENV['APP_BASE_PATH']
);- retrive instance of application
- Loads configuration.
- Initializes the Service Container.
- Register kernal
3. HTTP Kernal:
app/Http/Kernel.php - Receives the request.
- Runs global middleware.
- Passes the request to the router.
4. Router:
User request router decides which controller should execute.
5. Controller:
6. Model
7. View