F
Filament3mo ago
taz

Livewire components that implements HasForms can have multiple forms ?

How I can have multiple forms in a custom Livewire component that implements HasForms ? This Is my component and in my view I use {{ $this->form }} to render the form. I need a form for FirstModel AND SecondModel. Thanks you. Filament is awesome btw !
<?php

namespace App\Livewire;

use App\Models\SecondModel;
use App\Models\FirstModel;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;

class GetStarted extends Component implements HasForms
{
use InteractsWithForms;

public ?FirstModel $firsModel = null;

public ?SeconModel $secondModel = null;

public $name = '';
public $surname = '';


public $currentPage = 1;
public $totalPages = 4;

protected function getFormSchema(): array
{
return FirstModel::getForm();
}

public function create(): void
{
$this->firstModel = FirstModel::create($this->form->getState());
$this->nextPage();
}

public function render()
{
return view('livewire.get-started');
}
....
}
<?php

namespace App\Livewire;

use App\Models\SecondModel;
use App\Models\FirstModel;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Forms\Contracts\HasForms;
use Livewire\Component;

class GetStarted extends Component implements HasForms
{
use InteractsWithForms;

public ?FirstModel $firsModel = null;

public ?SeconModel $secondModel = null;

public $name = '';
public $surname = '';


public $currentPage = 1;
public $totalPages = 4;

protected function getFormSchema(): array
{
return FirstModel::getForm();
}

public function create(): void
{
$this->firstModel = FirstModel::create($this->form->getState());
$this->nextPage();
}

public function render()
{
return view('livewire.get-started');
}
....
}
1 Reply
Want results from more Discord servers?
Add your server