表单
代码编辑器
简介
代码编辑器允许你在文本框中显示行号编写代码。默认情况下,代码高亮并不启用。
use Filament\Forms\Components\CodeEditor;
CodeEditor::make('code')

语言语法高亮
使用 language()
方法,你可以修改代码编辑器的语言语法高亮。该编辑器支持 CSS、HTML、JavaScript、Json 和 PHP 的高亮。你可以打开 Filament\Forms\Components\CodeEditor\Enums\Language
枚举类查看它支持的全列表。比如,要启用 JavaScript 的语法高亮,你可以使用 Language::JavaScript
枚举值:
use Filament\Forms\Components\CodeEditor;
use Filament\Forms\Components\CodeEditor\Enums\Language;
CodeEditor::make('code')
->language(Language::JavaScript)
除了允许静态值外,language()
方法同时也接受通过函数动态设置其值。你可以将多个 utility 作为参数注入到该函数中。
Learn more about utility injection.
Utility | Type | Parameter | Description |
---|---|---|---|
Field | Filament\Forms\Components\Field | $component | The current field component instance. |
Get function | Filament\Schemas\Components\Utilities\Get | $get | A function for retrieving values from the current form data. Validation is not run. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent model FQN | ?string<Illuminate\Database\Eloquent\Model> | $model | The Eloquent model FQN for the current schema. |
Operation | string | $operation | The current operation being performed by the schema. Usually create , edit , or view . |
Raw state | mixed | $rawState | The current value of the field, before state casts were applied. Validation is not run. |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current schema. |
State | mixed | $state | The current value of the field. Validation is not run. |

Still need help? Join our Discord community or open a GitHub discussion