Fields
Although Wire configures field parameters of your model out of the box. You still need to modify them with more conventional types so it will output and insert the proper data.
A field would most likely look like:
'name' => [
'type' => 'text',
'available_in' => ['index', 'create', 'show', 'edit'],
'rules' => 'required|max:199'
],
type
and available_in
fields are required for any type of fields.
String fields are the most basic field in Wire, text
, number
, password
, date
are string fields. You do not have to set up anything specific for them, but they are validated
and inserted into the database
differently. Also, each type of field has a different component for outputting the data.
This is how a string field would be set:
'password' => [
'type' => 'password',
'available_in' => ['index', 'create', 'show', 'edit'],
'rules' => 'required|max:199'
],
Relational fields allow you to conveniently make relations between different objects.
You can have belongsTo
, belongsToMany
, hasOne
, or hasMany
fields.
To create a relationship between one identifier
and another, you need to define the relationship method
, and its Identifier
.
'category_id' => [
'type' => 'belongsTo',
'method' => 'category',
'identifier' => Category::class,
'available_in' => ['index', 'create', 'show', 'edit'],
],
The key for **belonsTo ** field should be same as the column_name
in the given table
.
belongsToMany
field allows multiple selections as an array, it's recommended to insert rules and add up max length for the array.
'tags' => [
'type' => 'belongsToMany',
'method' => 'tags',
'identifier' => Tag::class,
'available_in' => ['create', 'edit', 'show'],
'rules' => 'array|max:5|required'
],
hasOne
is very similar to hasMany
and it will allow you to create the sub-object when you are creating the main object.
'detail' => [
'type' => 'hasOne',
'method' => 'detail',
'identifier' => FooDetail::class,
'available_in' => ['show'],
],
hasMany
field will allow you to create a sub-object, you can create many sub-object that belongs to the main object afterward.
'details' => [
'type' => 'hasMany',
'method' => 'details',
'identifier' => FooDetail::class,
'available_in' => ['show'],
],
Unfortunately, Polymorphic fields are not allowed yet: morphOne
, morphTo
, and morphMany
.
Foor Storage
fields, if you do not define disk
, it will store the file into public
, also do not forget to run php artisan storage:link
to add a symbolic link to the /public
directory.
In addition to all of the available fields, there is an image field which will allow you to upload an image and automatically insert it into the table with the data. It's only stored when the entire object is validated including the image. But by default, the image will be randomly named.
'icon' => [
'type' => 'image',
'disk' => "public",
'available_in' => ['index', 'create', 'show', 'edit'],
],
File field allows you to store any kind of file into the application. It's not any different than the image field
'resume' => [
'type' => 'file',
'disk' => "resume",
'available_in' => ['index', 'create', 'show', 'edit'],
],
Uploading fiels to CDN will be allowed in feature versions.
In addition to relational selectable fields, you can also have a selection field with hardcoded options
'is_featured' => [
"type" => "select",
"options" => ["0" => "disabled", "1" => "active"],
'available_in' => ['show', "index", 'create']
],
You can also set a boolean field
'is_featured' => [
"type" => "boolean",
'available_in' => ['show', "index", 'create', 'edit']
],