From the course: Accelerating Laravel API Development with AI: From Specification to Testing
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Adding business logic (middleware) - Laravel Tutorial
From the course: Accelerating Laravel API Development with AI: From Specification to Testing
Adding business logic (middleware)
- [Instructor] Have you ever released code that meets all the expectations, but then you receive feedback about a missing, completely undocumented feature? Of course, that's how it works. Building web apps is iterative and missing pieces are discovered all the time. One cool feature in Laravel is middleware. Middleware is code that runs between a request and a response in an application. It's used to filter, modify, or inspect requests, handling things like authentication, rate limiting, or logging. Middleware keeps core logic clean by offloading reusable, cross-cutting concerns into focused, composable layers of functionality, and that makes middleware a perfect place to iterate on application-wide features. Jumping right in, I'll ask Copilot how I would add middleware for rate limiting. In a Laravel 12 application, how would I add rate limiting middleware? And, just kidding, Laravel has rate limiting built in. Sometimes adding or reminding of context can help you avoid writing code…