-
Notifications
You must be signed in to change notification settings - Fork 0
Properties
public $model;
public $form_data;
public $action;
public $formTitle;
public $showDelete = false;
public $showGoBack = true;
public $inline = true; //se Layout page
public $spaMode = false; //see Layout page
public $spaLayout = 'tall-forms::spa-layout'; //see Layout page
private static $storage_disk;
private static $storage_path;
public $form_wrapper = 'max-w-screen-lg mx-auto'; //see Styling page
Optional Eloquent model instance attached to the form component. This is passed in via the @livewire
blade directive.
Example:
@livewire('user-edit-form', ['model' => $user])
Example of using the model in the component success
method:
public function success()
{
$this->model->update($this->form_data);
}
An array of the current data present in the form. This data is keyed with each field name.
Example:
$name = $this->form_data['name'];
If it is a create
form you have to add the create($form_data)
method to your component and the $model
property should be set to null
Example Create form:
public function setup() {
$this->fill([
'action' => 'create',
'model' => null, //must be null in a create form, remove this and pass model to mount in an update form
]);
}
This is the default action type. If it is an update
form you do not need to do anything. All is done automatically by the form component.
- If
$spaMode = false
(default) the title is automatically displayed above the form. - If
$spaMode = true
you have to add{{ $formTitle }}
to yourpages.default
blade component where you want to display the form title see Layout. - Set
$formTitle = null
to hide the form title in all cases. - You can set a default formTitle in the config file. see Config
Example:
public function setup() {
$this->fill([
'formTitle' => 'Update User',
]);
}
Default = false. Set to true
if you want to show a delete button. Consider if you need to create a delete()
method in your form component.
This is the default delete method supplied by this package It checks if the model exists to avoid errors if trying to delete a model that hasn't been saved yet.
public function delete()
{
if (optional($this->model)->exists) {
$this->model->delete();
session()->flash('success', 'The object was deleted');
return redirect($this->previous);
}
return null;
}
Shows a button that saves the model and returns to a defined url. The default form component method uses a version of return back()
compatible with Livewire.
You can override the components default method:
public function saveAndGoBackResponse()
{
//default is redirect back()
return redirect()->route('some.route.name');
}
A static property which sets the disk to use for file uploads. Defaults to public
.
Example:
private static $storage_disk = 's3';
Or, via .env
to apply globally:
FORM_STORAGE_DISK="s3"
A static property which sets the path to use for file uploads. Defaults to uploads
.
Example:
private static $storage_path = 'avatars';
Or, via .env
to apply globally:
FORM_STORAGE_PATH="avatars"