Content::field()
Retrieve the value of a custom field on a content item, resolving translations and decoding multi-value types.
Since 1.0.0-rc.1
Source core/src/Models/Content.php
Content::field(string $key, ?int $languageId = null): mixed
Parameters
| $key | string | The field's machine key — e.g. 'price', 'sku', 'color'. |
| $languageId | int|null | Defaults to the current app locale's language ID. Only applies to translatable fields; ignored for non-translatable fields. |
Returns
mixed
String for scalar types, array for multi-value types (multi-select, media with `multiple: true`), null if the field doesn't exist or has no stored value.
Retrieves the value of a custom field attached to this content item via one of its content type's field groups.
How it resolves
- Find the field by
keywithin any group attached to this content's type. - If the field is translatable — look up the value for the requested language ID (defaults to current locale's ID).
- If the field is non-translatable — look up the value with
language_id IS NULL. - For multi-value types (
multi-select,media), the stored JSON string is decoded into an array.
Examples
Basic scalar field
{{ $content->field('price') }}
// 1299
With a specific language
{{ $content->field('title', $romanian->id) }}
// "Telefon mobil Samsung Galaxy"
Multi-select — decodes to array
@foreach($content->field('tags') as $tag)
<span class="tag">{{ $tag }}</span>
@endforeach
Missing field — returns null
$content->field('does-not-exist'); // null
Performance
The method caches results per-request. Calling $content->field('price') multiple times in the same request hits the DB once.
For high-traffic public pages, eager-load fieldValues and contentType.fieldGroups.fields when fetching the content to avoid N+1 queries.
See also
- Content model (index)
- Custom fields user guide
- Custom fields concept (coming)