Loading...
Loading...
Create custom MoonShine form fields with PHP classes, Blade views, Alpine.js interactivity, and proper data handling. Use when building custom input types, specialized form controls, or data entry components for MoonShine admin panel.
npx skill4agent add moonshine-software/forty-five moonshine-field.guidelines/fields-development.md.guidelines/fields-development.mdapp/MoonShine/Fields/resources/views/admin/fields/staticresolveOnApply()return $itemresolveOnAfterApply()viewData()valueattributeslabelcolumnerrorsvalueattributeslabelcolumnerrorssystemViewData(){{ $attributes }}uniqid()assets()protectedtoValue()toFormattedValue()resolvePreview()resolveValue()prepareBeforeRender()@php<input><select><textarea>resolveValue()resolvePreview().guidelines/fields-development.mdFieldTextTextareaSelectapp/MoonShine/Fields/FieldName.phpresources/views/admin/fields/field-name.blade.phpapp/MoonShine/Fields/YourField.phpresources/views/admin/fields/your-field.blade.phpviewData()protected function viewData(): array
{
return [
// Don't pass 'value' - it's AUTOMATICALLY available!
// Only pass YOUR custom data:
'isHighlighted' => $this->isHighlighted,
'maxStars' => $this->maxStars,
];
}resolveValue()protected function resolveValue(): mixed
{
return $this->toValue();
}resolvePreview()protected function resolvePreview(): Renderable|string
{
return (string) $this->toFormattedValue();
}resolveOnApply()protected function resolveOnApply(): ?Closure
{
return function (mixed $item): mixed {
data_set($item, $this->getColumn(), $this->getRequestValue());
return $item; // MUST return
};
}prepareBeforeRender()protected function prepareBeforeRender(): void
{
parent::prepareBeforeRender();
// Add attributes, prepare data here
}@props([
'value',
'attributes',
'label',
'column',
'errors',
'isHighlighted' => false,
])
<div {{ $attributes }}>
<input type="text" value="{{ $value }}" />
</div>