RDM LABSPORTUGUÊS

Technical article/ · 9 min read

Laravel's Starting Point: Before the First Command

A journey into the wonderful and intriguing world of Laravel!

Laravel Saga · Season 0 · Episode 00

Let me start with a question: have you ever written return view('home') inside a controller and stopped to think about what happens after that line?

If the answer is "no," don't worry. Most of us start that way. We create a route, write a controller, call a model, and everything works. Laravel is so well designed that you can build entire applications without ever opening the vendor/ directory. And that's great, until the day it isn't.

That day tends to arrive in very specific ways. A middleware that doesn't run in the order you expected. A BindingResolutionException that appears out of nowhere. A 419 error that only happens in production. An application that has become slow, and you have no idea where to start investigating. Or simply that uncomfortable feeling of using a powerful tool without truly understanding how it works.

This series was created to solve that problem.

What We'll Explore Together

The idea is simple to describe, but takes real work to accomplish: follow a single HTTP request from the moment it leaves the browser until the response comes back, opening every door it passes through along the way.

We'll go through the web server, PHP, the public/index.php file, the Service Container, Service Providers, the Kernel, middleware, the router, validation, controllers, the database, response construction, error handling, and finally, what happens after the user has already received the page.

By the end of this journey, the goal is for you to look at any Laravel behavior and confidently explain: "This happens here, because of this."

Why Not Start Directly with Laravel?

This was a deliberate decision, and I want to explain why.

Much of what looks like "magic" in Laravel isn't Laravel magic at all. It's HTTP, it's PHP, it's a design pattern that's been around for thirty years. Once you understand that HTTP is stateless, sessions and cookies stop feeling like arbitrary conventions. Once you understand that PHP "forgets" everything at the end of each request, it becomes clear why the framework boots the application again with every request and why tools like php artisan config:cache exist. Once you've built a dependency injection container with your own hands, Laravel's Service Container stops being a black box.

So I've divided the series into two parts.

Season 0: Laying the Groundwork

This season consists of eleven articles covering the fundamentals that support the framework. They don't focus on Laravel all the time, but every topic was chosen because it explains something that will come up later.

  1. How the Web Works: HTTP in Practice. Requests, responses, methods, status codes, headers, cookies, and CSRF protection.
  2. NGINX, Web Servers, and the Road to PHP. What happens between the internet and your code, and why everything eventually reaches index.php.
  3. What PHP Is and How It Executes. OPcache, PHP-FPM, and the execution model in which each request is born and dies independently.
  4. Modern PHP. Types, enums, attributes, and Reflection, the engine behind many of the framework's "magic" features.
  5. Composer, Autoloading, and PSRs. How thousands of files written by different authors work together.
  6. Object-Oriented Programming and SOLID in Practice. With a focus on interfaces and dependency inversion.
  7. Inversion of Control and Dependency Injection. We'll build a container from scratch.
  8. Classic Design Patterns Inside Laravel. Strategy, Adapter, Pipeline, Observer, Active Record, and others, each in the exact place where it appears.
  9. Software Architecture. From MVC to layered and hexagonal architecture, DDD, modular monoliths, and microservices.
  10. Software Engineering in the Age of AI. New patterns and how they build on older ones.
  11. The Laravel Ecosystem at a Glance. Where each tool fits, serving as a bridge into the main saga.

If you already know some of these topics well, feel free to skip them. Each article stands on its own. However, I recommend at least skimming the final summary of each one. That's where I connect the topic to what comes next in the saga.

The Saga: From Request to Response

Once we've established the foundations, we'll dive into Laravel itself. There will be a prologue and twelve chapters, following the actual order in which things happen inside the framework. Since the journey is long, the saga is divided into two seasons, following the natural geography of the journey itself.

Season 1: The Journey In, from the Entry Point to the Destination. Everything that happens before a single line of your controller code runs.

  • Prologue: The complete map of the journey.
  • Chapter 1: The entry point, public/index.php, and the birth of the application.
  • Chapter 2: The Service Container, the heart of the framework.
  • Chapter 3: Service Providers and Facades.
  • Chapter 4: The HTTP Kernel and the Pipeline pattern.
  • Chapter 5: Middleware, the gatekeepers of the application.
  • Chapter 6: Routing and route model binding.

Season 2: The Journey Back, from the Destination to the Response. The request finally reaches your code, then makes its way back to the browser.

  • Chapter 7: Requests, Form Requests, and validation.
  • Chapter 8: Controllers and authorization.
  • Chapter 9: The domain layer, including models, Eloquent, services, and actions.
  • Chapter 10: The response, and how any return value becomes HTTP.
  • Chapter 11: The error path, including exceptions and the handler.
  • Chapter 12: send(), terminate(), and life after the response.

Each chapter introduces the next one, so reading them in sequence is the most natural approach. But you can also use the saga as a reference: need to understand middleware today? Go straight to Chapter 5.

The request end to end, chapter by chapterpublic/index.php to Service Container. Service Container to Providers and Facades. Providers and Facades to HTTP Kernel. HTTP Kernel to Middleware. Middleware to Routing. Routing to Validation. Validation to Controller. Controller to Domain. Domain to Response. Response to send() and terminate(). Controller to Exceptions: something went wrong. Exceptions to Response: becomes HTTP. Scenario Season 1: The way in. Everything that happens before a single line of your controller runs, from the front door to the chosen route. Path: public/index.php, Service Container, Providers and Facades, HTTP Kernel, Middleware, Routing. Scenario Season 2: The way back. The request finally meets your code, then makes its way back to the browser. Path: Routing, Validation, Controller, Domain, Response, send() and terminate(). Scenario The error path. An exception along the way doesn't kill the request: the handler turns it into an HTTP response. Path: Controller, Exceptions, Response, send() and terminate().public/index.phpchapter 1Service Containerchapter 2Providers and Facadeschapter 3HTTP Kernelchapter 4Middlewarechapter 5Routingchapter 6Validationchapter 7Controllerchapter 8Domainchapter 9Responsechapter 10Exceptionschapter 11send() and terminate()chapter 12errorbecomes HTTPpublic/index.phpchapter 1Service Containerchapter 2Providers and Facadeschapter 3HTTP Kernelchapter 4Middlewarechapter 5Routingchapter 6Routingchapter 6Validationchapter 7Controllerchapter 8Domainchapter 9Responsechapter 10send() and terminate()chapter 12Controllerchapter 8Exceptionschapter 11Responsechapter 10send() and terminate()chapter 12errorbecomes HTTP

Season 1

The way in

Everything that happens before a single line of your controller runs, from the front door to the chosen route.

Season 2

The way back

The request finally meets your code, then makes its way back to the browser.

The error path

An exception along the way doesn't kill the request: the handler turns it into an HTTP response.

The request end to end, chapter by chapter

About Versions: Why Laravel 13?

This series uses Laravel 13 as its reference version. It was released in March 2026, requires PHP 8.3 or later, and is the current framework version as I write this.

Now, I know many people work on projects running older versions. That's why, whenever something works one way in Laravel 13 and differently in previous versions, you'll find a version note explaining the difference. Something like this:

Version note

In Laravel 13, the middleware responsible for CSRF protection is called PreventRequestForgery. In Laravel 11 and 12, it was called ValidateCsrfToken; in Laravel 10 and earlier, it was called VerifyCsrfToken and lived inside your application.

The good news is that the request lifecycle has changed very little over the years. The major structural shift happened in Laravel 11, when files such as app/Http/Kernel.php and app/Exceptions/Handler.php were removed from the default application skeleton and their responsibilities were incorporated into bootstrap/app.php. From Laravel 11 to 13, the changes have been more about developer ergonomics, such as new PHP attributes, than about architecture. So even if you're using Laravel 10, almost everything we'll cover still applies, and the version notes will explain the differences.

How the Articles Are Structured

All articles follow a similar structure, so you'll know what to expect:

  • An introduction that establishes where we are in the journey.
  • The main content, always with code examples you can copy and test.
  • Version notes, whenever there are relevant differences.
  • "What to Take Away from This Episode," a short summary of what really matters.
  • A preview of the next article.

As for the code, the examples are designed to run. Whenever a snippet is simplified, such as when I show a condensed version of an internal framework method, I'll let you know. And whenever possible, I'll include an Artisan command, a dd(), or a quick test so you can see things happening with your own eyes. Reading about a pipeline is useful; setting a breakpoint and watching it work is much better.

Who Is This Series For?

I wrote this series with three main types of readers in mind.

Developers who already use Laravel every day but feel they only know the framework "from the outside." You know how to create routes, controllers, and models, but you want to understand what's happening under the hood so you can debug more effectively, make architectural decisions with greater confidence, and stop relying on trial and error.

Beginners who want to build a solid foundation early on. Season 0 was made for you. It covers fundamentals that many developers only learn after years of experience.

Developers coming from another language or framework who want to understand how Laravel approaches things. You'll recognize many concepts under different names, and comparisons with other approaches will appear throughout the journey.

As for prerequisites, I only ask for one thing: basic familiarity with programming and PHP. You don't need to know what a container, a pipeline, or a service provider is. We'll build all of that together.

A Word About the Age of AI

You might be wondering whether it's still worth studying a framework's internals when coding assistants can generate controllers, tests, and migrations in seconds.

My answer is: it's more worthwhile than ever.

Writing code has become cheaper. Deciding what to write, reviewing what was written, and understanding why something doesn't work are still the job of someone who understands the system from the inside. An AI tool can easily generate a working three-hundred-line controller. Recognizing that it should have been a Form Request, an Action, and an event requires an understanding of the layers we'll study here.

That's why Season 0 includes an entire article on software engineering in the age of AI, and why Laravel 13, which already includes native AI tools, will appear throughout the series. But the focus remains on fundamentals. They're what continue to matter when the tools change.

How to Get the Most Out of This Series

Here are a few suggestions from someone who's been down this road:

Keep a project open while you read. It can be a new project created with laravel new studies. Run the examples, change things, break things. You'll learn more from an error you caused yourself than from ten paragraphs of explanation.

Open the framework's source code. The vendor/laravel/framework/src/Illuminate directory is surprisingly readable. Whenever I mention a class, look it up and read it. Before long, you'll find yourself navigating the framework naturally.

Use Artisan as a magnifying glass. Commands such as php artisan route:list -v, php artisan about, and php artisan tinker reveal the application's internal state. They'll come up frequently.

Don't rush. Each article is designed to be read at a comfortable pace. It's better to understand one chapter thoroughly than to get through three without retaining anything.

Let's Get Started

If you've made it this far, you've already understood the spirit of this series: less "memorize this command" and more "understand why it exists."

In the next article, we'll start at the very beginning, before PHP even enters the picture: the message your browser sends when you type an address and press Enter. We'll talk about HTTP, for real. It's the foundation everything else rests on, and I guarantee you'll look at your browser's Network tab differently after that.

See you in Episode 01.

References and Further Reading

Official Documentation

Keeping Up with the Ecosystem

  • Laravel News: Community news, releases, and tutorials.
  • Laracasts: Video lessons on Laravel, PHP, and software engineering.