Standard form
Requires an Eloquent Model
Using the Artisan make command:
make command:This command will create a new form component in app/Http/Livewire/Forms folder.
php artisan make:tall-form CreateUser --model=UserMake command options:
php artisan make:tall-form {name} {--model=Model} {--path=Http/Livewire/Forms} {--modelspath=Models} {--action=create} {--overwrite=false} {--skipexisting=false}Options, and their default values.
--path =
App/Http/Livewire/FormsOutput path.--modelspath =
Models. You can set this toApporAny\\Path\\With\\Backslash/Or/Slash.--action =
create. Options:create,edit,modal,no-buttons. Which stub to use.--overwrite =
false. WARNING: Overwrites ALL existing forms, without prompts.--skipexisting =
false.If false && overwrite=false, you'll be prompted to confirm overwriting EACH existing file.
Stubs
There are two stubs. One for
createforms and one forupdateforms.Defined by the
--actionparameter in the make command.The
--action=createstub is suitable for forms with optional route model binding.
Examples
Create a component in the Controllers directory
php artisan make:tall-form TestCommand --model=User --path=Http/Controllers/Livewire/FormsUse a model in the App directory, example: use App\User;
php artisan make:tall-form TestCommand --model=User --modelspath="App"Example
<?php
namespace App\Http\Livewire\Forms;
use App\Models\User;
use Tanthammar\TallForms\Input;
use Tanthammar\TallForms\TallFormComponent;
class CreateUser extends TallFormComponent
{
public function mount(?User $user): void
{
//Gate::authorize()
$this->mount_form($user); // $user from hereon, called $this->model
}
protected function formAttr(): array
{
return [
'formTitle' => 'User settings',
'wrapWithView' => false,
];
}
// OPTIONAL method, it already exists
protected function onCreateModel($validated_data): void
{
// Set the $model property in order to conditionally display fields when the model instance exists, on saveAndStayResponse()
$this->model = User::create($validated_data);
}
// OPTIONAL method, it already exists
protected function onUpdateModel($validated_data): void
{
$this->model->update($validated_data);
}
// OPTIONAL method, it already exists
protected function onDeleteModel(): void
{
$this->defaultDelete();
}
protected function fields(): array
{
return [
Input::make('Name')->rules('required'),
];
}Protip: you can add the FillsColumns trait to your model for automatic $fillables from database column names.
Last updated
Was this helpful?