Skip to content

Manager methods ​

Call these on the CustomFields facade (KenPrz\CustomFields\Facades\CustomFields). They work in the current scope. See Multi-tenancy.

Fields ​

MethodReturnsNotes
create(array $attributes)CustomFieldCreates the field in the current scope
update(CustomField $field, array $attributes)CustomFieldSame attributes as create, except model
find($id)?CustomFieldNull when missing, deleted or in another scope
findByKey($model, $key)?CustomFieldThe field that the current scope sees for that key
fieldsFor($model)Collection<string, CustomField>Every visible field, active or not, keyed by key
activate(CustomField $field)CustomFieldThe field accepts values again
deactivate(CustomField $field)CustomFieldRejects new values. Stored values stay readable.
reorder($model, array $keys)voidListed keys first, in order. The others keep their order after them.
delete(CustomField $field)voidSoft delete. Values are kept.
restore(CustomField $field)CustomFieldUndo a soft delete
forceDelete(CustomField $field)voidDeletes the field and all its values
dropIfExists($model, $key)voidForce delete a field by key, including a soft-deleted one. For migrations.

Checks and validation ​

MethodReturnsNotes
check(array $attributes)arrayEvery check that create() runs, without saving
keyError($model, $key)?stringWhy a key can't be used, or null
rules($model, bool $partial = false)arrayValidation rules keyed by field key
validate($model, array $input, bool $partial = false)arrayValidated, normalized values

Scope, types and cache ​

MethodReturnsNotes
forScope(?Model $scope)CustomFieldManagerA copy that works in the given scope
global()CustomFieldManagerA copy that sees global fields only
currentScope()?ModelThe scope this manager works in
registerType($name, $type)voidSee Custom field types
types()FieldTypeRegistrytypes()->names() lists every registered type
flush()voidForget loaded and cached definitions

$model can be a model instance, a model class or a morph alias.

Field attributes ​

AttributeTypeDefault
modelclass name or morph aliasrequired
keya-z, 0-9, _, starts with a letter, max 64required
labelstringrequired
typeregistered type namerequired
descriptionstringnull
settingsarray, merged over the type defaults[]
validation_ruleslist of Laravel rules[]
is_requiredboolfalse
is_activebooltrue
is_searchablebool, for your own usefalse
is_filterablebool, for your own usefalse
sort_orderint0

Released under the MIT License.