The Kernel instance calls handle, indicating that the laravel core and common code are ready and the project is officially running

Code: Http/Kernel/app/PHP

<? php namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; Class Kernel extends HttpKernel {// This is middleware that needs to be started before a route is called. Do not modify protected $middleware = ['Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode', 'Illuminate\Cookie\Middleware\EncryptCookies', 'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse', 'Illuminate\Session\Middleware\StartSession', 'Illuminate\View\Middleware\ShareErrorsFromSession', 'App\Http\Middleware\VerifyCsrfToken', ]; // This is the Middleware element we can use in router.php or Controller. You can customize many protected $routeMiddleware = ['auth' => 'App\Http\Middleware\Authenticate' 'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth', 'guest' => 'App\Http\Middleware\RedirectIfAuthenticated', 'test' => 'App\Http\Middleware\testMiddleWare', ]; }Copy the code

As you can see, there is no Handle in this file, only some property definitions, so the real Handle is implemented in the superclass

Code:… /Illuminate/Foundation/Http/Kernel.php

// This is very important. It is some boot items of the project. Among the important steps of Kernel, Protected $bootstrappers = [// To check that the environment variables are normal 'Illuminate\Foundation\ bootstrap \DetectEnvironment', // Get config file, Use app()->make('config') to view all the configuration information. 'Illuminate\Foundation\Bootstrap\LoadConfiguration' // bind an instance named log to the container. (app()->make('log')) 'Illuminate\Foundation\Bootstrap\ConfigureLogging', Illuminate\Foundation\Bootstrap\HandleExceptions'. // Create an alias for the aliases item in /config/app.php using the PHP library class_alias. We can use App::make(' App ') to get the instance 'Illuminate\Foundation\Bootstrap\RegisterFacades', // Register the providers of /config/app.php with the container 'Illuminate\Foundation\Bootstrap\RegisterProviders'. // Run the boot method 'Illuminate\Foundation\Bootstrap\BootProviders' on all serviceProviders registered in the container,]; Public function handle($request) {try {// Return $this->sendRequestThroughRouter($request); } catch (Exception $e) { $this->reportException($e); return $this->renderException($request, $e); } } protected function sendRequestThroughRouter($request) { $this->app->instance('request', $request); Facade::clearResolvedInstance('request'); $this->bootstrap(); $this->bootstrap(); // This is before scheduling the URL, that is, before running Route, Return (new Pipeline($this->app)) // do not interpret ->send($request) // need to run middleware included in $this->middleware ->through($this-> Middleware) // Then ($this->dispatchToRouter()) } // After the prelude, Protected function dispatchToRouter() {return function($request) {$this->app->instance('request', $request);  Return $this-> Router ->dispatch($request); }; }Copy the code

The Route operation is based on the URL and the /app/Http/routes.php file

File:… /Illuminate/Routing/Router.php

Public function dispatch(Request $Request) {$this->currentRequest = $Request; In version 4.2, Route has a filter attribute; $response = $this->callFilter('before', $request); If (is_null($response)) {$response = $this->dispatchToRoute($request); } $response = $this->prepareResponse($request, $response); In version 4.2, Route has a filter attribute; $this->callFilter('after', $request, $response); return $response; } public function dispatchToRoute(Request $request) { $route = $this->findRoute($request); $request->setRouteResolver(function() use ($route) { return $route; }); $this->events->fire('router.matched', [$route, $request]); $response = $this->callRouteBefore($route, $request); $response = $this->runRouteWithinStack($route, $request); $response = $this->runRouteWithinStack($route, $request); } $response = $this->prepareResponse($request, $response); $this->callRouteAfter($route, $request, $response); return $response; } // protected function runRouteWithinStack(Route $Route, $this->gatherRouteMiddlewares($route); $this->gatherRouteMiddlewares($route); Return (new Pipeline($this->container)) ->send($request) -> Through ($middleware) ->then(function($request) use ($route) { Return $this->prepareResponse($request, //run Controller $route->run($request)); }); } public function run(Request $request) { $this->container = $this->container ? : new Container; try { if ( ! is_string($this->action['uses'])) return $this->runCallable($request); Return $this->runWithCustomDispatcher($request); $this-> CustomDispatcher($request); Return $this->runController($request); } catch (HttpResponseException $e) { return $e->getResponse(); }} // Continue scheduling, finally scheduling to... / Illuminate/Routing/ControllerDispatcher. PHP file dispatch method protected function runWithCustomDispatcher $Request (Request) {  list($class, $method) = explode('@', $this->action['uses']); $dispatcher = $this->container->make('illuminate.route.dispatcher'); return $dispatcher->dispatch($this, $request, $class, $method); }Copy the code

File:… /Illuminate/Routing/ControllerDispatcher.php

public function dispatch(Route $route, Request $request, $controller, $method) { $instance = $this->makeController($controller); $this->assignAfter($instance, $route, $request, $method); $response = $this->before($instance, $route, $request, $method); $response = $this->callWithinStack($instance, $route, $request, $method); } return $response; } protected function callWithinStack($instance, $route, $request, $method) {// Again, Middleware...... Don't forget that Middleware can be added to controller constructors in the official documentation! $this->getMiddleware($instance, $method); $this->getMiddleware($instance, $method); // Again, Return (new Pipeline($this->container)) ->send($request) -> Through ($Middleware) $this->call($instance, $route, $method); then(function($request) use ($instance, $route, $method); }); }Copy the code

So that’s what’s going on between the entry file and the controller