Laravel Tutorials

Clean Up Your Code with the whenHas Method

Published

Struggling with optional form fields cluttering your code? The 'When Has' method offers a neat, efficient way to handle them.

Instead of juggling a bunch of if statements for something like email frequency, 'When Has' lets you simplify everything. You just check and update what you need without the mess.

Plus, if you're worried about missing data, 'When Has' has your back with easy default settings. It’s your handy fallback plan.

With 'When Has', you're ditching the chaos for a clearer, more straightforward approach. Trust me, once you try it, you’ll love how tidy your code can be!

Harris Raftopoulos photo

Senior Software Engineer • Staff & Educator @ Laravel News • Co-organizer @ Laravel Greece Meetup

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Image Dominant Color and HEIC Support in Laravel 13.24 image

Image Dominant Color and HEIC Support in Laravel 13.24

Read article
Official Laravel Zed Extension: LSP for PHP & Blade image

Official Laravel Zed Extension: LSP for PHP & Blade

Read article
Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD image

Laravel Head: Manage Meta Tags, Open Graph, and JSON-LD

Read article
PhpStorm 2026.2 Released image

PhpStorm 2026.2 Released

Read article
Laravel Doctor: Diagnose Your App With One Artisan Command image

Laravel Doctor: Diagnose Your App With One Artisan Command

Read article
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article