Fields represent the type and characteristics of your stream data. For example a "name" field would likely be a string field type.
Fields are strictly concerned with data. Please see the UI package for configuring field inputs.
Fields can be defined within the JSON configuration for your streams. You can get started by simply defining fields by handle
and their type
respectively.
// streams/contacts.json
{
"fields": {
"name": "string",
}
}
To define more information about the field use an array:
// streams/contacts.json
{
"fields": {
"name": {
"type": "string",
"name": "fields.name"
},
}
}
Define rules and validators for fields to merge them with other stream validation.
// streams/contacts.json
{
"rules": {
"name": [
"required",
"max:100"
],
"email": [
"required",
"email:rfc,dns"
],
"company": "required|unique"
}
}
The field type is responsible for validating and casting its specific data type.
The string
field type stores a string value. Other string-like fields may extend the string type.
{
"type": "string"
}
The url
field type stores a URL or named route.
{
"type": "url"
}
The hash
field type stores a one-way hashed string, great for passwords.
{
"type": "hash",
"config": {
"prefix": "string"
}
}
The encrypted
field type stores a two-way encrypted string.
{
"type": "encrypted"
}
The markdown
field type stores markdown formatted text.
{
"type": "markdown"
}
The select
field type stores a selection from a list of options.
{
"type": "select",
"config": {
"options": {
"first": "First Option",
"second": "Second Option"
}
}
}
Besides basic array and associated arrays, you may specify a callable:
{
"type": "select",
"config": {
"options": "\\App\\[email protected]"
}
}
The $fieldType
can then be injected in order to set the config.options
manually:
// app/CustomOptions.php
class CustomOptions
{
public function handle($fieldType)
{
$fieldType->config['options'] = [
// Your options
];
}
}
The array
field type stores array values.
{
"type": "array",
"config": {
"format": "json" // json|yaml
}
}
The multiselect
field type stores an array of selections from a list of options. The multiselect field type also supports callable options.
{
"type": "multiselect",
"config": {
"options": {
"first": "First Option",
"second": "Second Option",
"third": "Third Option"
}
}
}
{
"type": "boolean"
}
{
"type": "integer"
}
{
"type": "datetime"
}
{
"type": "date"
}
{
"type": "time"
}
{
"type": "entry",
"config": {
"stream": "handle"
}
}
{
"type": "entries",
"config": {
"stream": "handle"
}
}
{
"type": "relationship",
"config": {
"related": "stream"
}
}
{
"type": "multiple",
"config": {
"related": "stream"
}
}
{
"type": "file",
"config": {
"path": "storage/app/public/uploads"
}
}
{
"type": "image",
"config": {
"path": "storage/app/public/uploads/img"
}
}