/packages
following the vendor/package naming you entered. Creating a field in the admin ends in the same result. Within this folder, there are several key files./packages/{vendor/Field{package}/ui/field/
- you must run a CLI sync command for your changes to take effect within your website. Simply run this below with yarn/npm running, or build afterward:/packages/{vendor}/Field{package}/src/Field/Field{package}.php
is the primary method for API usage where you may adjust default settings. $storeRules
and $updateRules
are default validation rules that will be passed in when the field is used, such as with a module or page. An example would be an email field that would pass in an attribute to assure a proper email address:getStoreRules
and the getUpdateRules
methods, here's the method:getValue()
and setValue($value)
methods. This will be the default getter/setter for any package fields created. If a developer modifies the module file this field is attached to, a mutator would override the getValue/setValue methods.migrationCommand
method contains a string value of the migration command that will be run upon creation of a package field. The example should be pretty self-explanatory. Just keep in mind to go by the Laravel documentation on column modifiers, ensure ->nullable()
is attached unless the field is built for a specific website, and keep the same syntax standard seen in the default.shouldNotSetData
attribute and having it return true is mostly used for relationship fields. That way a hasMany
doesn't try to save data to a column that does not exist.formatColumnName
controls the value saved to the database for a package field, as does formatName
. It should be noted that the column name is set first.afterStore
and afterUpdate
are called after a package field is stored with this field type. You may use this to update configuration, sync custom database structure, or whatever else you would like.afterModelStore
and afterModelUpdate
methods are called, respectively. The same basic idea is used as with the above-after methods. For a relationship field, for example, we hook into this method to manually save data for a HasMany
relationship.withLoadedRelationships
, although it can be used for other purposes. Primarily it is used to dynamically define relationships, as first introduced in Laravel 7. Another important usage is loading relationships that will be returned to the VueJS layer. This second piece can be of great use for those building fields with specific purposes - such as a field for a particular website to achieve specific results. That way your code is still abstracted from the core CMS code, but can still load in the data you need.withFormMeta
is yet another helper method, this one allowing a field to pass in data within the create/edit actions. An example is that you need to pass in possible select-able values from the database to a select field.meta
column, you can create the method createFieldRules()
which should return an array of Laravel-supported validation rules. An example can be found below for the FieldPasswordConfirmation
field:updateFieldRules()
like the below:meta
info for use within these other views, or within the field PHP class file. An example of this is with FieldNumber
which allows customization of minimum value, maximum value, and increment/step value. We store these values in the database and can then use this when rendering the field with the above AdminField.vue
component.FieldPlace
, we need to do just that, have the user provide a Google API Key for use with Google Places. Here is our implementation as an example below:config
array key. Simply pass in key and default values (or null), then a settings page will be viewable within the fields admin section - you'll see a pink button with a cog icon where the user can then put in their configuration.options
array - this can also be configured to set defaults when a package field is created from your field type. Being a location lookup field, we don't want to require the field by default, nor allow it to be sortable or searchable (the former could work though).action_rules
which enable, or disable showing the field on the relevant page. With the place field, we don't want it showing on the index page nor the search, but should be shown on the create, edit, and show pages when browsing a module.withFormMeta
called withSettingsFormMeta
. Below is an example from FieldImage
which returns full image meta for use. The model is whichever settings is used for - so for site types, it would be the site type model and have media attached to it to retrieve.