Free tutorial · 27 lessons
Laravel Tutorial
Learn Laravel, the most popular PHP framework, step by step: routing, controllers, Blade templates, requests and validation, middleware, the database with migrations and Eloquent, relationships, collections, authentication, authorization, queues, events, caching, Artisan commands and testing. Every example runs on Laravel 13 and is shown with its real output.
Laravel Basics
- Laravel Introduction — What Laravel is, why it's the most popular PHP framework, and what a Laravel route looks like.
- Laravel Get Started — Install Laravel, create a project, and learn the folder structure and the commands you'll use every day.
- Laravel Routing — Define routes for each HTTP method, name them, group them with prefixes, and return strings, arrays or responses.
- Route Parameters and Model Binding — Capture parts of the URL, make them optional, constrain them with patterns, and let Laravel load Eloquent models from IDs automatically.
- Laravel Controllers — Move request handling out of route files into controller classes, use single-action and resource controllers, and inject dependencies.
- Blade Templates — Render HTML with Blade: echo values safely, use @if, @foreach and @forelse, build layouts with components and slots.
- Laravel History & Versions — How Laravel began as one developer's alternative to CodeIgniter in 2011, how it became the most popular PHP framework, every major version on one timeline with its support dates, and which version to use today.
Requests and Responses
- Laravel Requests and Input — Read query strings, form fields, JSON bodies, headers and files from the Request object, with defaults and type helpers.
- Laravel Validation — Validate input with rules like required, email, min and unique; get automatic 422 JSON errors; and move complex rules into Form Request classes.
- Responses, JSON and API Resources — Build responses with status codes and headers, return JSON, and shape your API output with API Resource classes instead of exposing models directly.
- Laravel Middleware — Run code before and after requests: authentication checks, logging, headers and rate limits. Write your own middleware and apply it to routes and groups.
- Errors, Exceptions and Logging — Stop requests with abort(), throw custom exceptions that render their own responses, report errors to logs, and know what debug mode changes.
Database and Eloquent
- Migrations — Create and change database tables in version-controlled PHP files: columns, indexes, foreign keys, and rolling changes back.
- The Query Builder — Query the database fluently with DB::table(): where clauses, ordering, aggregates, joins and grouping, with bindings that prevent SQL injection.
- Eloquent Models — Map tables to model classes, create, read, update and delete records, protect against mass assignment, cast attributes, and add accessors and query scopes.
- Eloquent Relationships — Connect models with hasMany, belongsTo, belongsToMany and hasOne, query through relationships, and avoid the N+1 problem with eager loading.
- Laravel Collections — Laravel's Collection class wraps arrays with dozens of chainable methods: map, filter, groupBy, sum, sortBy, pluck, keyBy, chunk and more. Eloquent results are collections too.
- Factories and Seeders — Generate realistic fake data for development and tests with model factories and states, and fill the database with seeders.
- Pagination — Split long lists into pages with paginate(), simplePaginate() and cursorPaginate(), and return JSON with page links for APIs.
Beyond the Basics
- Authentication — How users sign in with Laravel: hashed passwords, Auth::attempt, the current user, starter kits for full login flows, and Sanctum for API tokens.
- Authorization: Gates and Policies — Decide what a signed-in user may do with gates for simple checks and policies for model rules, then enforce them in routes, controllers and Blade.
- Queues and Jobs — Move slow work like emails, image processing and API calls out of the request with queued jobs; retry failures; and run workers with Horizon or queue:work.
- Events, Listeners and Notifications — Decouple your code with events and listeners, and send notifications to users over mail, database, SMS or Slack channels.
- Caching — Store expensive results with Cache::remember, choose a cache store (Redis, database, file), invalidate correctly, and use atomic locks.
- Artisan Commands and Scheduling — Write your own Artisan commands with arguments, options and output, and schedule tasks to run every minute, hour or day.
- Testing Laravel Apps — Write feature tests that send requests and assert on responses and the database, use RefreshDatabase and factories, and fake mail, queues and HTTP calls.
- The Service Container and Providers — Understand how Laravel builds objects: automatic dependency injection, binding interfaces to implementations, singletons, and swapping implementations in tests.