### Install via Composer Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Installs the package via Composer. ```bash composer require jeffersongoncalves/filament-yaml-editor ``` -------------------------------- ### Full Form Field Example Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Full example of the form field with all common options. ```php YamlEditorField::make('config') ->height(400) ->withToolbar() ->castState() ->autoFormat() ->dark() ->rules(['yaml']) ->placeholder("# paste your YAML here\n") ``` -------------------------------- ### Build assets with pnpm Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Install dependencies and build the package assets after modifying JS or CSS sources. The package ships with pre-compiled assets in resources/dist/. ```bash pnpm install pnpm build ``` -------------------------------- ### Eloquent YamlCast Example Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Eloquent cast to automatically convert between YAML strings and arrays. ```php use JeffersonGoncalves\FilamentYamlEditor\Casts\YamlCast; class Setting extends Model { protected $casts = [ 'config' => YamlCast::class, ]; } ``` -------------------------------- ### YamlCast Eloquent cast Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Eloquent cast that stores YAML as text in the database and retrieves it as a PHP array. `get()` parses YAML string to array (returns `null` for null/empty); `set()` dumps array to YAML string using `Yaml::dump($value, 4, 2)` (returns `null` for null). ```php use JeffersonGoncalves\FilamentYamlEditor\Casts\YamlCast; class Server extends Model { protected function casts(): array { return [ 'config' => YamlCast::class, ]; } } // Usage $server->config = ['key' => 'value']; // Stored as YAML text $server->config; // Returns array ``` -------------------------------- ### Run composer analyse and format Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Run static analysis with PHPStan at level 5 and format code with Laravel Pint. ```bash composer analyse # PHPStan level 5 composer format # Laravel Pint ``` -------------------------------- ### Publish Config File Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Optionally publishes the config file. ```bash php artisan vendor:publish --tag=filament-yaml-editor-config ``` -------------------------------- ### Run composer test Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Run the package test suite. ```bash composer test ``` -------------------------------- ### Publish Assets Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Publishes the package assets. ```bash php artisan filament:assets ``` -------------------------------- ### Run pnpm dev watch mode Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Run the development watch mode for rebuilding assets automatically during development. ```bash pnpm dev ``` -------------------------------- ### Import ViewYamlAction Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Import statement for the ViewYamlAction class. ```php use JeffersonGoncalves\FilamentYamlEditor\Actions\ViewYamlAction; ``` -------------------------------- ### Infolist Entry Usage Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Displays YAML content in a read-only CodeMirror editor within an infolist. ```php use JeffersonGoncalves\FilamentYamlEditor\Infolists\Components\YamlEditorEntry; YamlEditorEntry::make('config') ->height(400) ->dark() ``` -------------------------------- ### View YAML in Table Action Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Use ViewYamlAction in a Filament table to view YAML content in a modal. Configure the column and editor height. ```php use JeffersonGoncalves\FilamentYamlEditor\Actions\ViewYamlAction; public static function table(Table $table): Table { return $table ->columns([...]) ->actions([ ViewYamlAction::make() ->column('config') ->editorHeight(500), ]); } ``` -------------------------------- ### Read-Only YAML Display in Infolist Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Use YamlEditorEntry in a Filament infolist to display YAML content read-only. Configure with a label, height, and column span. ```php use JeffersonGoncalves\FilamentYamlEditor\Infolists\Components\YamlEditorEntry; public static function infolist(Infolist $infolist): Infolist { return $infolist->schema([ YamlEditorEntry::make('config') ->label('Configuration') ->height(400) ->columnSpanFull(), ]); } ``` -------------------------------- ### ViewYamlAction table/page action Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Creates a modal action to view YAML content from a record. The `column()` method is required and specifies the model attribute containing the YAML data; supports dot notation via `data_get()`. Default modal editor height is 400 pixels. ```php use JeffersonGoncalves\FilamentYamlEditor\Actions\ViewYamlAction; // In a Filament table or page ViewYamlAction::make() ->column('config') // Required: the model attribute to display ->editorHeight(500) // Modal editor height (default: 400) ->dark() // Force dark theme ->light() // Force light theme ``` -------------------------------- ### Table Action for Filament v3 Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Usage for Filament v3 (branch 1.x) to add a table action. ```php ->actions([ ViewYamlAction::make() ->column('config'), ]) ``` -------------------------------- ### Conditional Toolbar and Theme Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Configure YamlEditorField with conditional toolbar, height, and read-only state based on user permissions. ```php YamlEditorField::make('config') ->withToolbar(fn () => auth()->user()->isAdmin()) ->height(fn () => auth()->user()->isAdmin() ? 600 : 300) ->readOnly(fn () => ! auth()->user()->can('edit-config')) ``` -------------------------------- ### Table Action for Filament v4/v5 Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Usage for Filament v4/v5 (branches 2.x and 3.x) to add a table action that opens a modal with YAML content. ```php ->recordActions([ ViewYamlAction::make() ->column('config') // required: the model attribute to display ->editorHeight(500) // optional, default 400 ->dark(), // optional ]) ``` -------------------------------- ### YamlEditorEntry infolist entry Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Displays YAML content read-only in an infolist. Automatically handles array and string states; arrays are dumped to YAML using `Yaml::dump($state, 4, 2)`. ```php use JeffersonGoncalves\FilamentYamlEditor\Infolists\Components\YamlEditorEntry; YamlEditorEntry::make('config') ->height(300) // Editor height in pixels (default: 300) ->dark() // Force dark theme ->light() // Force light theme ``` -------------------------------- ### Model with YAML Column Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Use YamlCast to cast a model attribute to YAML. The migration stores YAML as text in a 'steps' column. ```php use JeffersonGoncalves\FilamentYamlEditor\Casts\YamlCast; class Pipeline extends Model { protected function casts(): array { return [ 'steps' => YamlCast::class, ]; } } // Migration Schema::create('pipelines', function (Blueprint $table) { $table->id(); $table->text('steps'); // Store YAML as text $table->timestamps(); }); ``` -------------------------------- ### Basic Form Field Usage Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Basic usage of the form field with toolbar and YAML validation. ```php use JeffersonGoncalves\FilamentYamlEditor\Forms\Components\YamlEditorField; YamlEditorField::make('config') ->withToolbar() ->rules(['yaml']) ``` -------------------------------- ### Global yaml validator extension Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Uses the globally registered `yaml` validator extension in any validation context. The `yaml` rule is automatically replaced with the `ValidYaml` instance. ```php // Works in any validation context $request->validate([ 'config' => 'required|yaml', ]); ``` -------------------------------- ### YAML Config Editor with Validation Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Use YamlEditorField in a Filament form to edit YAML with validation. The field is configured with a label, height, toolbar, state casting, auto-formatting, and validation rules. ```php use JeffersonGoncalves\FilamentYamlEditor\Forms\Components\YamlEditorField; public static function form(Form $form): Form { return $form->schema([ YamlEditorField::make('config') ->label('Server Configuration') ->height(500) ->withToolbar() ->castState() ->autoFormat() ->rules(['required', 'yaml']) ->columnSpanFull(), ]); } ``` -------------------------------- ### ValidYaml Rule Usage Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/README.md Validation rule usage both as a rule object and as a string alias. ```php use JeffersonGoncalves\FilamentYamlEditor\Rules\ValidYaml; // As a rule object $request->validate([ 'config' => ['required', new ValidYaml], ]); // As a string alias (registered by the service provider) $request->validate([ 'config' => ['required', 'yaml'], ]); ``` -------------------------------- ### YamlEditorField form field configuration Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Configures a YAML editor form field with height, toolbar, state casting, auto-formatting, read-only mode, theme, and validation. The `rules(['yaml'])` automatically applies the `ValidYaml` rule. Default height is 300 pixels. ```php use JeffersonGoncalves\FilamentYamlEditor\Forms\Components\YamlEditorField; YamlEditorField::make('config') ->height(400) // Editor height in pixels (default: 300) ->minLines(10) // Minimum number of lines ->withToolbar() // Enable toolbar (format, copy, expand) ->castState() // Auto-convert between array and YAML string ->autoFormat() // Auto-format YAML on load ->readOnly() // Disable editing ->dark() // Force dark theme ->light() // Force light theme ->rules(['yaml']) // Validate YAML syntax ->required() ``` -------------------------------- ### Add custom validation after yaml rule Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Add custom validation rules after the 'yaml' rule to check the parsed structure when the ValidYaml rule only checks if Yaml::parse() succeeds. ```php YamlEditorField::make('config') ->rules(['yaml']) ->afterStateUpdated(function ($state) { $parsed = Yaml::parse($state); // Validate structure... }) ``` -------------------------------- ### ValidYaml validation rule Source: https://github.com/jeffersongoncalves/filament-yaml-editor/blob/3.x/resources/boost/skills/yaml-editor-development/SKILL.md Validation rule that checks if a string contains valid YAML. Skips validation for non-string or blank values. Error messages include the YAML parse error details. Can be used standalone or automatically via the `'yaml'` string in `rules()`. ```php use JeffersonGoncalves\FilamentYamlEditor\Rules\ValidYaml; // Standalone usage $request->validate([ 'config' => ['required', new ValidYaml], ]); // In YamlEditorField (auto-applied) YamlEditorField::make('config') ->rules(['yaml']) // 'yaml' string is auto-replaced with ValidYaml instance ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.