Laravel

By the end of PHP you can build a working PHP application by hand: a front controller, a router made of match arms, PDO with prepared statements, sessions, CSRF tokens, password hashing, a templating convention and a folder layout you invented. Every one of those pieces works. The trouble starts with the second developer, who has to learn your conventions before touching anything, and with the tenth feature, when the hand-written router, the ad hoc validation and the SQL scattered through page scripts start to cost more than the features themselves.

Laravel 2,157 is the answer most PHP teams reach for. It keeps everything PHP taught (it is plain PHP 8.5, served by the same Apache and PHP-FPM, talking to the same MySQL 524 ), and replaces the parts you would otherwise rewrite for every project with conventions that thousands of developers already share. A route file instead of a switch, Eloquent models instead of hand-mapped rows, migrations instead of SQL files emailed between colleagues, a queue instead of a cron job that sends mail in the request, and a test suite that boots the whole application in memory.

This chapter builds one application throughout: the bookshop from MySQL and PHP, with its customers, categories, products, orders and reviews, now running on Laravel 13 against MySQL. Each section adds a layer: routes and controllers, Blade views, validation, migrations and Eloquent, authentication and authorization, queues and mail, an API, tests and a production deployment. The SQL that Eloquent generates is shown alongside the PHP wherever it matters, because MySQL is the reason you can judge whether that SQL is any good.

The chapter closes with Other PHP Frameworks, a short survey of the other PHP frameworks you may inherit, and an honest account of when Laravel is the wrong choice.

What you will learn

Sections