# Standard form

### Using the Artisan `make` command:

This command will create a new form component in `app/Http/Livewire/Forms` folder.

```
php artisan make:tall-form CreateUser --model=User
```

### **Make 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/Forms` Output path.
* **--modelspath** = `Models`. You can set this to `App` or `Any\\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 `create` forms and one for `update` forms.
* Defined by the `--action` parameter in the make command.
* The `--action=create` stub 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/Forms
```

Use a model in the `App` directory, example: `use App\User;`

```
php artisan make:tall-form TestCommand --model=User --modelspath="App"
```

## Example

```php
<?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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tina-hammar.gitbook.io/tall-forms/form/form-types/standard-form.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
