Laravel Tips

329 tips
RSS

Practical engineering tips for Laravel developers and the wider PHP ecosystem. Got a tip in mind? Contributions are always welcome.

Laravel Collections

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...

1 min read
READ
Laravel Utilities

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...

2 min read
READ
Laravel Storage

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...

3 min read
READ
Git Workflow

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...

4 min read
READ
Laravel Collections

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...

4 min read
READ
Git GitHub Actions

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...

3 min read
READ
Git GitHub Actions

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...

3 min read
READ
Git GitHub Actions

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...

4 min read
READ
Laravel Database

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...

3 min read
READ
Laravel Database

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...

1 min read
READ
Laravel Queue

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...

3 min read
READ
Git Workflow

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...

4 min read
READ
Laravel Database

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...

2 min read
READ
Laravel Eloquent

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...

2 min read
READ
Laravel Eloquent

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...

2 min read
READ
Git Workflow

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...

3 min read
READ
Laravel Utilities

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...

4 min read
READ
Laravel HTTP & API

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....

2 min read
READ
Laravel Queue

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...

2 min read
READ
Laravel Storage

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...

2 min read
READ
Laravel HTTP & API

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...

2 min read
READ
Laravel Database

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...

2 min read
READ
Laravel HTTP & API

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...

3 min read
READ
Laravel Queue

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...

2 min read
READ

// Got a tip or want to contribute? github.com/MrPunyapal/tips