The Laravel Core: Demystify The Beast
Christoph Rumpel



Going on a journey through three parts. Request lifecycle, facades and Eloquent

Common excuses for not going through the source

Why should you care?

It speaks to you, become better at debugging, learn from the best, become a better developer


Let's begin in the public/index.php file.

Send the request through the router (and Facade::clearResolvedInstance so we get a fresh instance). Then bootstrap (load environment variables, config, service providers)

Return a new pipeline with the app, send a request, then process middleware, then dispatch to the router

In the request and router (Illuminate/Routing/Router), findRoute. Only one route gets matched though, and we need to run it!


People are passionate about their reaction towards Facades (magic! proxies! misleading! tightly-coupled! "Bad practice"!)


Route::get('conference, function() {
  $year = Request::get('year');

The request facade just has a getFacadeAccessor that returns 'request'

Base facade calls static::getFacadeRoot(). If it's not there, runtime exception. Otherwise, return $request->$method(...$args)

There are some advantages and disadvantages.

Misleading? Maybe, especially at the beginning with how it works. Hard to test? Nah. Tightly-coupled? Sure. Bad practice? Well, what is bad practice? We're not sanitizing bad input or stuff like that, we're passing everything faithfully along. You don't have to use them, but they have their advantages. And Taylor does like using Facades!


Object-Relational Mapper, Active Record, Models, Builders

Example today: "speakers", "conferences", "conference_speaker" with many-to-many relationship

No static "where" method in base Model, but there is a __callStatic($method, $parameters) function that returns (new static)->$method(...$parameters);

In model, well, there's a __call method that checks if the method is increment or decrement, and if not, return $this->forwardCallTo($this->newQuery());

Found the where method! It was in Eloquent/Builder.php!

What about first? Eloquent/Builder through a BuildsQueries trait

What about the relationship between the conference and speakers? I mean, we have a belongsToMany response from speakers(), but there's another magic __get($key) call that gets returns $this->getAttribute($key);

getAttribute checks if the array key exists between the key and list of attributes...speakers isn't there, but maybe it's a relationValue? Call getRelationValue() and there we go!

Eloquent is super powerful and cool.

Master your tools. Laravel is one of them. now with Pro! Turns out you can't make a living giving videos for free :p