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

tinkerwell logo
Tinkerwell

Enjoy coding and debugging in an editor designed for fast feedback and quick iterations. It's like a shell for your application – but with multi-line editing, code completion, and more.

Visit Tinkerwell

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article