Skip to main content

Laravel API Development Guide

About this guide​

A 22-chapter guide to using Laravel as an API backend. Blade and frontend features are left out; it covers only what an API that returns JSON needs.

What this guide aims at is not "code that works" but "code you can run in production." Every chapter points out the places where following a tutorial gives you something that works and then breaks in production. The order API, for instance, double-allocates stock when two requests arrive at once. The listing API returns other people's data even after you write a Policy. We pick up these traps in the order you meet them.

What makes this guide different
  • API only: no Blade, Livewire, or Inertia anywhere. Every chapter is about an API that returns JSON
  • One consistent subject: an e-commerce order system, grown over 22 chapters. Each chapter picks up where the last left off
  • What matters in production: every chapter has a dedicated section on what breaks when you use the feature in production
  • A modern baseline: targets Laravel 13 (released March 2026) and PHP 8.3

How this guide is structured​

Chapter outline​

Build the foundation (chapters 1-4)

#ChapterOverview
01IntroductionThe gap between code that works and code you can operate. The subject, and the endpoints of the finished system
02The request lifecycleThe path one request takes. bootstrap/app.php and the service container
03Modeling and seedingTable design, migrations, enum casts, factories, and seeders
04Routing and your first endpointapiResource(), route model binding, and versioning

From request to response (chapters 5-10)

#ChapterOverview
05Validating inputFixing the boundary of shape checking with a Form Request
06Where business logic belongsDismantling the Fat Controller. Service classes and the service container
07Designing the outputDeciding the shape of a response explicitly with an API Resource
08The listing APIPagination, filters, and spotting N+1
09Error designTranslating exceptions into HTTP responses
10TestingPinning down API behavior with Pest

Protect the API (chapters 11-13)

#ChapterOverview
11AuthenticationToken authentication with Sanctum. Moving guest orders onto user accounts
12AuthorizationGates and Policies. Why a Policy does not take effect on the listing API
13Middleware and rate limitingYour own middleware, verifying webhook signatures, and RateLimiter

Handle heavy work safely (chapters 14-18)

#ChapterOverview
14Transactions and concurrencyClosing double-allocated stock with row locks and conditional updates. Stopping resubmissions with a unique constraint
15Events and notificationsNotification and Mailable. Measuring the cost of sending synchronously
16Queue basicsJob classes, dispatch, and queue:work
17Queues in productionIdempotency, retries, failed_jobs, and restarting workers
18CachingKey design, stampede protection, and invalidation strategy

Supporting features and operations (chapters 19-22)

#ChapterOverview
19File storageUploads, signed URLs, and generating PDFs in a job
20The task schedulerCollapsing scheduled work into a single cron line
21Logging, monitoring, and deploymentStructured logs, handling sensitive data, and the deployment procedure
22SummaryA pre-release checklist

Who this is for​

  • People who can write basic PHP and are about to build an API in Laravel
  • People who have finished a Laravel tutorial but do not know what to watch for in production
  • People building the frontend separately who want to use Laravel purely as an API

Prerequisites​

RequirementKnowledgeNotes
RequiredBasic PHP 8 syntax (variables, arrays, control flow, functions)All chapters
RequiredClasses, methods, constructors, type declarations, namespacesAll chapters. The design principles themselves are covered in the PHP Class Design Guide
RequiredBasic terminal use and installing with ComposerChapter 2 onward
RecommendedBeing able to read SQL SELECT / INSERT / UPDATEChapter 3. You do not need to be able to write it
RecommendedHaving heard of HTTP GET / POST and how a URL is structuredChapter 4
Not requiredLaravel experienceThis guide starts from the basics
Not requiredTesting experienceChapter 10 starts from the basics

How to read it​

  • New to Laravel: read from chapter 1 in order, running the code as you go
  • Comfortable with the basics, here for operations: skim just the "What matters in production" section in each chapter, then read the body of the ones that catch your eye
  • Using it as a reference: open the relevant chapter directly from the outline above

What this guide does not cover​

TopicWhy
Blade / Livewire / Inertia / ViteBecause the premise is using Laravel as an API. The frontend is assumed to be built separately
Broadcasting (Reverb / Echo)The client side becomes a JavaScript implementation, which does not fit a guide that leaves the frontend out
Passport / OAuth2The official position is "Passport only if you need OAuth2." Chapter 11 gives just the criteria for choosing
JWTA Practical Guide to Laravel × DDD × Clean Architecture devotes a chapter to it
DDD tactical patterns and layered Clean Architecture implementationsSame guide. This one stays with Laravel's standard structure
Index design and normalization theoryThe Database Design Guide covers these
Laravel's AI features and vector searchNew in Laravel 13, but they take us away from the basics of API development
Docker / server provisioning / CI/CDChapter 21 is limited to configuration on the Laravel side
On the overlap with existing guides

Laravel explained from a class design angle currently also appears in the second half of the PHP Class Design Guide. Once this guide is complete, the Laravel part of that one is due to be merged into this guide.