---
title: "Typed field values — Forms for Laravel | Roundly"
description: "Each field type maps to a value type, so answers read back as int, bool, dates or arrays and mismatches fail validation."
url: https://roundly-consulting.com/open-source/docs/forms-for-laravel/typed-values
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Forms for Laravel](https://roundly-consulting.com/open-source/docs/forms-for-laravel.md)

# Typed field values

Each field type maps to an attributes AttributeType (see forms.field\_types), so stored values read back as real PHP types instead of raw strings, and submitted values are type-checked during validation:

```php
Forms::submissions($form)->first()->values;
// ['age' => 42, 'subscribed' => true, 'born' => CarbonImmutable, 'tags' => ['a', 'b']]

// One per-field row (a `Submission`) reads its own value the same way:
$row = $form->fields->firstWhere('key', 'age')->submissions()->first();
$row->typedValue();                      // 42 (int); true (bool) for a `checkbox` row
```

## Default mappings

| Field types | AttributeType | Reads back as |
| --- | --- | --- |
| `number, range` | integer | int |
| `float, decimal` | float | float |
| `checkbox, boolean, toggle` | boolean | bool |
| `date, datetime` | datetime | CarbonImmutable |
| `multiselect, checkboxes, tags` | array | array |
| `time and anything else` | string | exactly as stored |

## Type checking

After Laravel’s rules pass, each visible, non-null value whose field maps to a non-string type is checked against that type. A mismatch fails Forms::validate() (and finalize) with a ValidationException under the field’s path, like any other rule — a decimal in a number() field is one. The message names the expected type in words, in the current locale — “must be a valid list”, not “a valid array” — from forms::messages.types.\*. Unlisted field types — time among them — keep the free-form string behaviour:

```php
use Illuminate\Validation\ValidationException;

// 'age' => '3.5' posted to a number() field in the contact form's details group
try {
    Forms::validate($form, $request);
} catch (ValidationException $e) {
    $e->errors(); // ['contact.details.age' => ['The Age field must be a valid integer.']]
}

$field->attributeType(); // the AttributeType mapped from the field's type
```

A stored value that no longer converts — data written before a type change, or straight through createSubmission() — reads back exactly as stored instead of breaking the reader.

## Adding your own types

Valid AttributeType values are string, integer, float, boolean, array and datetime. The published field\_types array replaces the defaults, so keep the entries you still need. number and range are whole numbers — use a decimal or float field for fractions; a time field is unmapped on purpose (validate it with e.g. date\_format:H:i):

```php
// config/forms.php — keep the defaults and add your own field types
'field_types' => [
    'number' => 'integer',
    'checkbox' => 'boolean',
    // ...
    'rating' => 'integer',   // a custom field type, cast and checked as an int
],
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/forms-for-laravel.md)
