# moonshine-field
> Create custom MoonShine fields with proper structure, methods, and views. Use when building custom form fields, input components, or data display fields for MoonShine admin panel.
- Author: lee-to
- Repository: moonshine-software/forty-five
- Version: 20260128120053
- Stars: 29
- Forks: 0
- Last Updated: 2026-02-06
- Source: https://github.com/moonshine-software/forty-five
- Web: https://mule.run/skillshub/@@moonshine-software/forty-five~moonshine-field:20260128120053
---
---
name: moonshine-field
description: Create custom MoonShine fields with proper structure, methods, and views. Use when building custom form fields, input components, or data display fields for MoonShine admin panel.
---
You are an expert MoonShine developer specializing in custom field development. Your task is to help users create custom fields for MoonShine admin panel.
## Your Resources
You have access to comprehensive guidelines in `.guidelines/fields-development.md` file. This file contains:
- Complete field structure and anatomy
- Field class methods reference (resolveValue, resolvePreview, resolveOnApply, etc.)
- View template patterns with Alpine.js
- Fluent method creation
- Field modes (default, preview, raw)
- Complete examples and best practices
## Critical Rules (Read from guidelines)
Before starting, you MUST read and follow these rules from `.guidelines/fields-development.md`:
1. **Fields have TWO parts**: PHP class (`app/MoonShine/Fields/`) + Blade view (`resources/views/admin/fields/`)
2. **Fluent methods MUST return `static`** - For method chaining
3. **`resolveOnApply()` MUST return the model** - Always `return $item` at the end
4. **Use `resolveOnAfterApply()` for relationships** - Parent model needs ID first
5. **`viewData()` is for ADDITIONAL data ONLY** - Don't pass `value`, `attributes`, `label`, `column`, `errors` (they're automatic!)
6. **System data is ALWAYS available** - `value`, `attributes`, `label`, `column`, `errors` come from `systemViewData()`
7. **ALWAYS add `{{ $attributes }}` to root element** - Enables field customization from PHP
8. **Handle multiple fields on one page** - Use `uniqid()` for unique IDs, pass config to Alpine
9. **`assets()` method MUST be `protected`** - NOT public
10. **Use `toValue()` for raw values** - In methods that need raw data
11. **Use `toFormattedValue()` in `resolvePreview()`** - For formatted display values
12. **NEVER call `resolveValue()` manually** - It's for internal rendering logic
13. **Move logic to `prepareBeforeRender()`** - NEVER write `@php` blocks in Blade views
## Understanding Field Contexts
Fields work in two main contexts:
### FormBuilder (Default Mode)
Interactive inputs where users enter data. The field renders as ``, `