Validations for presence are ambiguous with key value styles

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the data category.

Last Updated: 2024-03-28

Validation for presence is ambiguous when working with key/value structures.

I had the following Laravel validation in a controller:

<? php
    $request->validate([
        'plan_name' => 'required',
    ]);

The validation was passing - even though plan_name was undefined. This was because the plan_name KEY was present in the request, but its VALUE had been set to undefined.

What I realy wanted was to ensure additionally that plan_name, the key itself, was present too (i.e. not null).