Laravel
25 notes
Best Practices
-
Avoiding N+1
The N+1 query problem is one of the most common performance pitfalls in Laravel applications. It hap...
-
Cache Invalidation Strategies
"There are only two hard problems in computer science: cache invalidation and naming things.&qu...
-
Caching
Caching sits between your application and its slowest operations — database queries, external API ca...
-
Contextual Attributes
Laravel 11 introduced contextual attributes, a cleaner way to tell the service container which concr...
-
Custom Collections
Laravel's Collection class is already powerful, but there are times when your domain logic benefits...
-
Eloquent Builder vs Scopes
Laravel gives you several ways to organise reusable query logic. Choosing between a custom Eloquent...
-
Form Request Validation Patterns
Form Request classes are Laravel's dedicated mechanism for validation and authorisation. Moving vali...
- Health Checks
-
Immutable Dates
Date handling is a frequent source of bugs. Laravel defaults to using Carbon, which is mutable — cal...
-
Logging
Laravel wraps the popular Monolog library behind a clean, unified interface. You get multiple log ch...
- Mass Assignment Guarding
-
Monitoring & Alerting
A Laravel application in production needs more than just error logs. You need visibility into whethe...
-
Performance Improvements
Small changes to how you query data, cache results, and load relationships can make a significant di...
-
Prune Data
Add prunable trait to Laravel model, set the prunable method to select the prunable dates.
-
Queue
Queues let you defer time-consuming tasks — sending emails, processing uploads, generating reports —...
-
Rate Limiting
Rate limiting protects your application from abuse — whether that is brute-force login attempts, API...
-
Read/Write DB Splitting
Read/write splitting offloads SELECT queries onto one or more read replicas while directing INSERT,...
-
Route Organisation & Naming
Well-organised routes are easier to maintain, easier to debug, and produce URLs that are easy to rea...
- Scheduled Tasks
- Secrets & Config Validation
- Security Headers
-
Using Env
The .env file is the standard place to store environment-specific configuration in Laravel. It keeps...
-
Working with Large Datasets
Loading an entire table into memory works fine for small datasets. It does not work when your table...
-
Laravel Coding Standards
This document focuses specifically on Laravel framework conventions and best practices. It assumes y...
-
Laravel Pint: Opinionated PHP Code Style Fixer
Laravel Pint is an opinionated PHP code style fixer built on top of PHP-CS-Fixer. It provides zero-c...