Reader Stacks

How to Validate a Checkbox as 'Accepted' in Laravel

An unchecked checkbox sends no value at all in the request, not false — Laravel's accepted rule exists specifically to handle this quirk correctly.

How to Validate a Checkbox as 'Accepted' in Laravel

Validating that a checkbox (like a "terms and conditions" agreement) was actually checked has a genuine quirk worth understanding — an unchecked HTML checkbox sends no field at all in the request, not a false value, which is exactly the behavior Laravel's accepted rule is built to handle correctly.

The basic checkbox and validation rule

 I agree to the terms
$request->validate([
    'terms' => 'accepted',
]);

accepted passes only when the field's value is "yes", "on", 1, "1", true, or "true" — and crucially, it also correctly fails when the field is missing from the request entirely, which is exactly what happens when the checkbox was left unchecked.

Why a plain required rule doesn't work correctly here

// this does NOT reliably validate a checkbox correctly
'terms' => 'required',

required fails on a missing or empty field, which happens to work for an unchecked box — but it would also incorrectly accept a checkbox sent with a value of "0" or false from custom JavaScript, since neither is empty by required's definition. accepted is the rule specifically designed for this exact scenario, checking for a genuinely truthy value rather than just non-emptiness.

accepted_if: requiring acceptance only under a condition

$request->validate([
    'marketing_consent' => 'accepted_if:newsletter_signup,true',
]);

Following the conditional validation approach covered elsewhere on this site, accepted_if combines the accepted-checkbox logic with a condition on another field — useful when a checkbox only needs to be checked under a specific circumstance rather than unconditionally.

Displaying the validation error in the view


@error('terms')
    You must agree to the terms and conditions.
@enderror

Handling the checkbox value on the model side

$user->update([
    'terms_accepted' => $request->boolean('terms'),
]);

$request->boolean() is the reliable way to convert the checkbox's request value into an actual PHP boolean for storage — it correctly returns false for a missing field (an unchecked box), rather than requiring a manual isset() check before assignment.

A multi-checkbox array, for comparison


$request->validate([
    'interests' => 'array',
    'interests.*' => 'in:sports,music,tech',
]);

A group of checkboxes representing a multi-select array is a genuinely different validation scenario from a single agree/accept checkbox — this needs the array and per-item validation approach covered for array validation elsewhere on this site, not the accepted rule, which is specifically for a single true/false checkbox.