-
Notifications
You must be signed in to change notification settings - Fork 0
V2 upgrade guide
tanthammar edited this page Sep 4, 2020
·
1 revision
- New stubs, create.stub and update.stub
- Fix for checkboxes, automatically becomes array data
- Breaking change: Deleted mount() from form component
- Breaking change: renamed setup() to afterFormProperties()
- New LegacyForm trait to bridge breaking changes
- New Relationship field type
- New Custom field type
- Updated
make
command to support multiple stub files - New DefaultMount trait for slim components
Sometimes breaking changes are needed to improve usability.
- the
mount()
method is removed from the form component- The mount() method was removed from the Form component to give you more freedom on which parameters you want to pass in your blade files. Having it in the main component also removes the need to support feature requests on what should be the default values. It was also necessary to move it to fully support Laravel Livewire Route model binding.
-
setup()
method renamed toafterFormProperties()
- When deciding to make a breaking change, method names, inherited from an old package, was renamed. The new names improve code readability. All the form property methods now have a more logical naming:
- beforeFormProperties()
- setFormProperties()
- afterFormProperties() (previously setup)
- When deciding to make a breaking change, method names, inherited from an old package, was renamed. The new names improve code readability. All the form property methods now have a more logical naming:
The easy way to upgrade to v2, is to use the new LegacyMount
trait in existing components.
- search for
extends FormComponent
to find your forms - add the trait and all will work as it did before
- the trait calls the old setup() method so you do not need to change anything in your existing code.
use Tanthammar\TallForms\FormComponent;
use Tanthammar\TallForms\Traits\LegacyMount;
class SomeForm extends FormComponent
{
use LegacyMount;
If you want to fully upgrade but keep your components slim you can use the DefaultMount trait instead. But be aware that it only accepts a $model
property.
use Tanthammar\TallForms\Traits\DefaultMount;
class SomeForm extends FormComponent
{
use DefaultMount;
The default mount method
// observe prevoius properties that are removed
// mount($model = null, $action = 'update', $showDelete = false)
public function mount($model = null)
{
$this->mount_form($model);
}
The old setup() method is still kept in the form component for legacy support, but all new components will not have that method and the stubs
have been modified accordingly.
Old stub:
public function setup() {
// form props where set here
}
New stub - create form
public function mount()
{
//Gate::authorize()
$this->fill([
'formTitle' => config('tall-forms.form-title'), //new config option
'action' => 'create',
'spaMode' => true, // config option available for custom blade view
'showGoBack' => false, //or true
]);
$this->mount_form();
}
New stub - update form.
public function mount(Model $model) //supports Route::livewire model binding
{
$this->fill([
'formTitle' => config('tall-forms.form-title'), //new config option
'action' => 'update',
'spaMode' => true, //config option available for custom blade view
'showGoBack' => false, //or true
]);
$this->mount_form($model);
}
See updated documentation in the wiki