12/28/2023 0 Comments Initialize eloquent model with arrayProtected function getFormModel(): string In this situation, you may call the model() and saveRelationships() methods on the form after the instance has been created:įorms\Components\SpatieTagsInput::make('tags'), In this case, you will pass the model class instead, but any field relationships will need to be saved manually after. For example, in a form that creates a post, the post model instance cannot be passed to the form before it has been submitted. In some cases, the model instance is not available until the form has been submitted. Protected function getFormModel(): Post // When registering a model to the form or component, these relationships will be automatically saved to the pivot table when getState() is called: Some fields, such as the Select, Repeater, SpatieMediaLibraryFileUpload, or SpatieTagsInput are able to interact with model relationships.įor example, Select can be used to attach multiple records to a BelongstoMany relationship. Protected function getFormModel(): string // You may receive some of the same benefits of registering a model by registering its class instead:įorms\Components\TextInput::make('title')įorms\Components\Select::make('categories') You may now use field relationships #Registering a model class Pass a model instance to a form using the getFormModel() method:įorms\Components\SpatieTagsInput::make('tags')->model($this->post), // Automatically attaching relationships to the model when the form is saved, when using fields such as the Select, Repeater, SpatieMediaLibraryFileUpload, or SpatieTagsInput.Automatically retrieving the database table name when using database validation rules like exists and unique.The form builder is able to use this model to unlock DX features, such as: You may transform the value that is dehydrated from a field using the dehydrateStateUsing() method. Field relationships, if they are defined, are saved.Any pending file uploads are stored permanently in the filesystem.Validation rules are checked, and if errors are present, the form is not submitted.Protected function getFormSchema(): array This is done with the fill() form method, often called in the mount() method of the Livewire component.įor your fields to hold data, they should have a corresponding property on your Livewire component, just as in Livewire normally. You must initialize forms when the Livewire component is first loaded. Visit your Livewire component in the browser, and you should see the form components from getFormSchema(). Protected function getFormSchema(): array // įorms\Components\TextInput::make('title')->required(),įorms\Components\MarkdownEditor::make('content'),
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |