If you've built a site in plain PHP, you know the feeling. Every file starts with include 'header.php'. Then you open a mysqli connection to the database, then you write if ($_POST['email']) to check the form. On the next project you write all of it again from the beginning.
Laravel is a PHP framework: a set of ready-made parts, plus rules about where each kind of code goes. Picture a restaurant kitchen. Each worker in that kitchen has a match in Laravel:
- The waiter reads the order and takes it to the right station in the kitchen. In Laravel, this is the route: a rule that matches the requested address with the code that answers it.
- The cook does the cooking. This is the controller: the code that does the work for a request to that address.
- The pantry holds the ingredients. This is the model: the code that holds the data from the database.
- The plating station arranges the dish before it goes out. This is the view: what people see.
With plain PHP you build that kitchen yourself from nothing. With Laravel the kitchen is already there, and you only have to cook.
Why use a framework
Plain PHP can build a website, but you write every small thing yourself: matching addresses to code, building SQL queries (commands for the database), checking form input, storing passwords safely, sending email. Laravel already brings all of it:
| Need | In Laravel | Taught in |
|---|---|---|
| Address to code | Routing | Routing |
| Code per feature | Controller | Controller |
| HTML pages | Blade | Blade Templating |
| Database tables | Migrations and Eloquent | Migrations, Eloquent |
| Checking input | Validation | Validation |
| Background work | Queues and Jobs | Queue & Job |
Laravel is written in PHP. Taylor Otwell has been building it since 2011. The version used here is Laravel 13, which needs PHP 8.3 or newer. Laravel also comes with Artisan, a command line tool (you run it by typing commands in a terminal window) for creating files, running the server and much more. All Artisan commands start with php artisan.
Create a project and run it
Throughout this track we build one app: a Library, to keep track of books and loans. Create the project with Composer, a PHP tool that downloads packages (ready-made code written by other people). Then start its server. A server is a program that answers requests from the browser.
composer create-project laravel/laravel library
cd library
php artisan serve
The terminal answers:
INFO Server running on [http://127.0.0.1:8000].
Press Ctrl+C to stop the server
composer create-project laravel/laravel librarydownloads Laravel into a newlibraryfolder, installs all its packages, creates the.envfile and sets up an SQLite database (a database stored in one file).cd librarymoves into that folder.php artisan servestarts a server for learning on your own computer, athttp://127.0.0.1:8000. As long as this terminal stays open, you can open the app in the browser.Ctrl+Cstops the server.- There's also the installer,
laravel new library, which asks a few questions first. The result is the same project.
Other options for installing and running Laravel:
| Way | When to pick it |
|---|---|
composer create-project, then php artisan serve (used in this track) |
learning: PHP and Composer are enough, and only the server runs |
laravel new library, npm install, then composer run dev |
the way the Laravel 13 docs show. composer run dev starts the server, a queue worker (a program that runs jobs in the background) and Vite at once, at http://localhost:8000 |
| php.new | PHP isn't installed yet: one command from that site installs PHP, Composer and the Laravel installer |
| Laravel Herd | macOS or Windows: one app that installs PHP and Nginx. Projects in the Herd folder open right away at a .test address |
Open http://127.0.0.1:8000 in the browser. You will see Laravel's default welcome page. When you change some code, save and refresh. The change shows right away, and you don't need to stop the server.
The folder map
These are the folders and files you open most often in a Laravel project:
| Folder or file | What's in it |
|---|---|
routes/web.php |
the list of addresses and the code that answers them |
app/Http/Controllers/ |
controllers, one class per feature |
app/Models/ |
models, one class per database table |
resources/views/ |
Blade templates, .blade.php files |
database/migrations/ |
recipes for creating tables |
public/index.php |
the front door: every request comes through here |
.env |
secret settings: the app key, the database password |
The journey of one request
The way Laravel divides the work is called the MVC pattern (Model, View, Controller). This table follows one request in the Library app later on, when you open GET /books/1. GET is the method (the kind of request) that the browser sends when you open an address.
| Step | Where | What happens |
|---|---|---|
| 1 | public/index.php |
Laravel starts and reads the request |
| 2 | routes/web.php |
the route /books/{id} matches, id = 1 |
| 3 | BookController@show |
the controller is called with $id = 1 |
| 4 | The Book model |
book number 1 is fetched from the database |
| 5 | The books.show view |
Blade builds the HTML |
| 6 | Response | the browser gets 200 OK and the "The Rainbow Troops" page |
The number in the server's answer (the response) is called the status: 200 means it worked, 404 means the address was not found. If no route matches, for example for GET /about, steps 3 to 5 never run. Laravel answers 404 right away with a page that says 404 | Not Found.
Your first route
The simplest route needs no controller and no view. Add this to routes/web.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/hello', function () {
return response()->json(['message' => 'Hello from Laravel!']);
});
use Illuminate\Support\Facades\Route;makes the nameRouteusable in this file.Route::get('/hello', ...)registers the address/hellofor theGETmethod.function () { ... }is the code that answers a request to that address.response()->json([...])turns the PHP array into JSON (a text format for exchanging data) and answers with status200.
Open http://127.0.0.1:8000/hello and the browser shows {"message":"Hello from Laravel!"}. So for this route one file is enough, routes/web.php, not three files (route, controller and view). Controllers and views are only needed once the code starts to grow.
In the exercise, the simulator runs your route and prints a transcript: GET /hello → 200, then the JSON body (the content of the answer) on the next line.
⚠️ What stalls your first day
- The server isn't running. If the terminal running
php artisan serveis closed, the browser only shows127.0.0.1 refused to connect. That message is not an error in your code. Start the server again. - Editing a
routes/api.phpthat doesn't exist. A new Laravel project has noroutes/api.phpyet. The API file is created withphp artisan install:api, and the addresses in that file automatically start with/api. - Committing
.env. Committing a file means saving it into Git (a tool that records the history of your code), and from there it can be uploaded to the internet. The.envfile holds the app key and passwords. It is already listed in.gitignore(the list of files Git ignores). Keep it that way. - Changing the sentence. The exercise looks for the exact text
Hello from Laravel!, capital letters and exclamation mark included.
TL;DR: Laravel is a PHP framework: a set of ready-made parts and rules about where code goes. It already brings routing (matching addresses to code), controllers, Blade (HTML pages), the database (Eloquent), validation (checking input) and queues (background work). Create a project with Composer (a PHP tool that downloads ready-made code): composer create-project laravel/laravel library. Then start its server (a program that answers the browser) with php artisan serve, and open http://127.0.0.1:8000. The pattern is MVC: the route matches the address, the controller does the work, the model holds the data, and the view builds what people see. An address with no route is answered with 404 | Not Found. For your first endpoint (an address that answers requests), one Route::get('/hello', ...) in routes/web.php that returns response()->json([...]) is enough.
⚡ Create a project, then run it
Write:
composer create-project laravel/laravel library
cd library
php artisan serve
Meaning: Laravel is a PHP framework: a set of ready-made parts for building websites. In the terminal (the window where you type commands), composer create-project downloads Laravel into a new library folder and prepares its settings file, .env. cd library moves into that folder. php artisan serve starts a server (a program that answers the browser's requests) at http://127.0.0.1:8000 for as long as the terminal stays open. Ctrl+C stops the server.
⚡ Each part has its own job
Guess first: a route matches an address with code, and a controller is the code that does the work for the request. You open GET /about, but no route matches. Does a controller get called?
No. Laravel answers 404 | Not Found right away. The controller, the model and the view never run.
Meaning: Laravel divides the work with the MVC pattern (Model, View, Controller). The route matches the address. The controller does the work. The model holds the data from the database. The view builds the HTML people see.
⚡ A first route needs one file
Write:
Route::get('/hello', function () {
return response()->json(['message' => 'Hello from Laravel!']);
});
Meaning: Route::get registers the address /hello. The function inside it is the code that answers that address. response()->json([...]) turns the PHP array into JSON (a text format for data) and answers with status 200, which means it worked. Write this route in routes/web.php. That one file is enough, with no controller or view needed yet.
In the exercise, the sentence Hello from Laravel! must match exactly, capital letters and exclamation mark included.