Laravel Tips
329 tipsPractical engineering tips for Laravel developers and the wider PHP ecosystem. Got a tip in mind? Contributions are always welcome.
Group Consecutive Items with chunkBy()
Use chunkBy() to split a Collection whenever the resolved value changes, without manually comparing items with the previous chunk. Before Laravel 13.30, grou...
Use Immutable Dates by Default in Laravel
Configure Laravel's Date facade to use CarbonImmutable by default, and automate migrating legacy Carbon calls with Rector. By default, Carbon instances in PH...
Harden Filesystem Operations with Storage::path() Traversal Protection in Laravel 13.30
Laravel 13.30 automatically normalizes and validates paths in Storage::path(), throwing a PathTraversalDetected exception if a path attempts to escape the co...
Git Submodule vs. Git Subtree: Which Should You Use?
A practical comparison of Git Submodules and Git Subtrees to help you choose the right strategy for embedding one repository inside another. When managing pr...
Simplify Collection Operations with Higher-Order Messages
Laravel Collections support higher-order messages through dynamic properties, allowing operations like each, map, filter, and groupBy to work directly with a...
Cache Playwright and Puppeteer Browsers in GitHub Actions
Cache browser binaries with actions/cache to avoid downloading 150MB+ on every CI run. Playwright and Puppeteer download full browser binaries (Chromium, Fir...
Write Files Incrementally in Build Scripts to Avoid Unnecessary Rebuilds
Compare generated content against existing files before writing. This prevents unnecessary git diffs, cache invalidation, and downstream rebuilds. Build scri...
Skip Expensive CI Steps Using git diff Instead of File Timestamps
File modification timestamps are unreliable in GitHub Actions. Use git diff to detect actual changes and conditionally skip expensive workflow steps. Many bu...
Query AI Embeddings with MariaDB Vector Distance in Laravel 13.27
Laravel 13.27 adds native vector distance query support for MariaDB 11.7+, enabling semantic search and similarity filtering directly through the query build...
Precise Binary String Comparisons with whereBinary() in Laravel 13.27
Laravel 13.27 adds whereBinary() to the query builder, replacing manual whereRaw() expressions for exact byte-level string comparisons. When querying case-se...
Monitor Aggregate Queue Metrics with Total Size Helpers in Laravel 13.27
Laravel 13.27 adds totalPendingSize(), totalDelayedSize(), and totalReservedSize() to the Queue facade, making it easy to aggregate queue metrics for dashboa...
Apply Individual Commits Across Branches with Git cherry-pick
Use git cherry-pick to apply specific commits from another branch to your current branch without merging the entire branch history. When working across multi...
Mask Query Bindings in Laravel Exception Messages
Keep query bindings out of QueryException messages while retaining access to the actual bindings. When a database query fails, Laravel's QueryException messa...
Refresh and Pessimistically Lock Models with refreshForUpdate() in Laravel 13.27
Laravel 13.27 adds refreshForUpdate(), reloading an existing model instance in-place with fresh database attributes while acquiring an exclusive FOR UPDATE r...
Scope Pivot Table Queries with Closures in wherePivot() in Laravel 13.26
Laravel 13.26 allows wherePivot() and orWherePivot() to accept closures, enabling direct reuse of local scopes defined on custom Pivot models. When querying...
Ignore Local Files Without Modifying .gitignore Using .git/info/exclude
Use .git/info/exclude to ignore personal scratch files, local debug scripts, and notes without polluting your team's shared .gitignore file. When working on...
Process Improvements in Laravel 13.26: Idle Timeouts and Testing Assertions
Laravel 13.26 introduces ProcessIdleTimedOutException to distinguish idle processes from overall runtime timeouts, alongside new testing assertions for execu...
Stream CSV Downloads in Laravel Without Creating Temporary Files
Combine response()-streamDownload(), php://output, and query chunking to stream CSV exports directly to the browser without writing temporary files to disk....
Debounce Queued Event Listeners with #[DebounceFor] in Laravel 13.26
Laravel 13.26 extends the #[DebounceFor] attribute to queued event listeners, collapsing bursts of repeated events into a single execution based on the lates...
Lazy Storage Migration with Read-Through Filesystem Disks in Laravel 13.26
Laravel 13.26 introduces the read-through filesystem driver, combining primary and fallback storage disks to migrate files lazily as they are requested. Migr...
Reusable API Configuration with Laravel HTTP Client Macros
Use Http::macro() to encapsulate repeated authentication, base URLs, and shared headers into reusable HTTP client instances across your application. When int...
Use Database Expressions for Dynamic Migration Defaults
Pass an Expression instance to Laravel's migration default() method to define raw SQL functions, dynamic timestamps, and calculated defaults directly in your...
Laravel 13.25 Reverses Merge Order in Request::all()
In Laravel 13.25, Request::all() now gives submitted input precedence over uploaded files when their keys collide, while file() continues to provide direct a...
Centralized Queue Routing with Queue::forward() in Laravel 13.26
Laravel 13.26 introduces Queue::forward() to reroute queued jobs to new queue names, different connections, or both without modifying job classes or dispatch...
No matching tips found
Try adjusting your search query or choosing another category/subcategory filter.
// Got a tip or want to contribute? github.com/MrPunyapal/tips