Laravel Tips

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.

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.

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 an item's property or method without writing boilerplate callbacks.

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 access to uploaded files.

READ >
Laravel Configuration

Use config() Instead of env() in Application Code

Call env() only inside configuration files and use config() throughout your application code to prevent missing values when configuration is cached.

READ >
Laravel Database

Load Large SQL Dumps in Laravel Seeders

Use DB::getSchemaState()->load() to load large reference SQL dump files in seeders, with DB::unprepared(file_get_contents(...)) as a fallback for older Laravel versions.

READ >
Laravel Queue

Handle Skipped Unique Jobs with UniqueJobSkipped

Laravel 13.25 adds the UniqueJobSkipped event, allowing applications to react whenever a unique queue job is skipped because a duplicate instance is already active.

READ >
Laravel Eloquent

Simplify ULID Foreign Keys with foreignUlidFor()

Laravel 13.25 adds foreignUlidFor() to the migration Blueprint, allowing you to define ULID foreign key columns and table constraints directly from model classes.

READ >
Laravel Validation

Optimize Large Wildcard Array Validation in Laravel 13.24

Laravel 13.24 introduces dramatic performance optimizations for validating large nested arrays with wildcard rules, reducing validation execution time from 85 seconds to under 1 second.

READ >
Filament Admin Panel

Move Filament Global Search to Sidebar

Customize your Filament admin panel layout by moving the global search bar to the top of the navigation sidebar.

READ >
Laravel Configuration

Monthly Log Rotation with Laravel 13.23

Laravel 13.23 adds a built-in monthly logging driver that rotates log files once per month instead of daily.

READ >
Laravel Configuration

Squash Legacy Database Migrations Carefully

Use php artisan schema:dump to collapse hundreds of old migration files into a single SQL schema file while preserving new migrations.

READ >
PHP Tooling

Typed Arrays and Array Shapes in PHP with PHPDoc

Document and enforce structured array schemas using PHPDoc array shapes, lists, and non-empty array annotations for static analysis in PHPStan and Psalm.

READ >
Laravel Routing

Secure Actions with Temporary Signed URLs

Generate tamper-proof, time-limited URLs for email verification, invoice downloads, and passwordless logins with URL::temporarySignedRoute().

READ >
Laravel Routing

Handle Unmatched Routes with Route::fallback()

Use Route::fallback() at the end of your routes file to serve custom 404 views, API error payloads, or Single Page Application (SPA) entry points.

READ >
Laravel Utilities

Mask Sensitive Information with Str::mask()

Use Str::mask() to obfuscate portions of email addresses, phone numbers, and payment details for secure display in user interfaces.

READ >

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