# Types of fields
Lyra includes the most commonly used data types.
# Text field
The text field is the simplest of the editable fields, it will display a text entry.
Text::make('Name')
# URL field
It shows a clickable link in the index and show views.
Url::make('Link')
# Slug field
Displays a text field with a slug pattern filter
Slug::make('Slug')
In addition to the functionality of the Text field, it has the sluglify
method to auto-generate the slug from another existing field.
This method requires the name of the column in the source field.
Text::make('Title'),
Slug::make('Slug')->sluglify('title'),
The slug will be created automatically as you type in the source field, as long as there is no previous value in the 'Slug' field when you access the form.
# Textarea field
Muestra un elemento textarea con posibilidad de expandirlo verticalmente.
Textarea::make('Description')
# Password field
Displays a password type input field, always displays a placeholder even if it has a value and saves a hash of the password.
Password::make('Password')
# Date field
Displays a date type entry field
Date::make('Birth')
# DateTime field
Displays a datetime field with date and time.
DateTime::make('Published At')
# File field
This field allows the upload of any type of file.
File::make('Attachment')
# Field Image
It allows the upload of images offering a preview of the same.
Image::make('Thumbnail')
# Field Markdown
Shows the EasyMDE editor for Markdown.
Markdown::make('Body')
# Boolean field
This field is used to represent a boolean value, it shows a ✔️ when the value is true, and an ❌ if the value is false.
Boolean:make('Active')
You can set the true and false values if, for example, you have an enum field in your database, to do this you must use the values
method.
This method requires two parameters, the first will be the true value and the second will be the false value.
Boolean:make('Status')->values('ACTIVE', 'FALSE')
In addition, you can set whether you want it to be marked as default or not.
If you want it to be checked you must use the checked
method.
Boolean:make('Active')->checked()
# Select field
This field shows a selectable drop-down list with multiple options, which options must be added to the field using the options
method.
Select::make('Status')->options([
'Draft', 'Pending', 'Published'
])
You can also use an associative array, the key will be saved in the database and the value will be displayed in the drop-down list.
Select::make('Status')->options([
'draft' => 'Draft',
'pending' => 'Publish pending', 'published' => 'Published'
])
To define a default value you must use the default
method.
Select::make('Status')->options([
'Draft', 'Pending', 'Published'
])->default('Draft')
Select::make('Status')->options([ 'draft' => 'Draft',
'pending' => 'Publish pending', 'published' => 'Published'
])->default('draft')
# Radio field
This field shows a group of radio buttons, you must specify the available options using the options
method.
Radio::make('Status')->options(['Draft', 'Pending', 'Published'])
You can also use an associative array, the key will be saved in the database and the value will be displayed next to each radio button.
Radio::make('Status')->options([
'draft' => 'Draft',
'pending' => 'Publish pending',
'published' => 'Published'
])
To define a default value you must use the default
method.
Radio::make('Status')->options([
'Draft', 'Pending', 'Published'
])->default('Draft')
Radio::make('Status')->options([
'draft' => 'Draft',
'pending' => 'Publish pending',
'published' => 'Published'
])->default('draft')
# Heading field
This field does not correspond to any column in the database. It shows a separator to group different fields in the show and edit views.
Heading::make('Meta')
You can also display HTML code which will be rendered by the user's browser.
Heading::make('Extra data - <span style="color:red">Important</span>')
# Code field
The field will display the CodeMirror editor.
This field supports multiple modes, to specify a mode you must use the mode
method.
The available modes are:
- clike
- htmlmixed
- javascript
- sql
- shell
- powershell
- css
- dockerfile
- go
- http
- markdown
- php
- python
- sass
- scheme
- diff
- vue
- xml
- yaml
Code::make('Body')->mode('htmlmixed')
If you want to use JSON in this field, you must use the json
method.
Code::make('Options')->json()