Table Repeater in modalContent
I'm having trouble persisting the data from my modal's table repeater after creating my resource.
CreateCar. many-to-many relationship
modal.blade:
Class AddExampleModal
public function getFormActions(): array
{ return [ ...parent::getFormActions(),
Action::make('add example')
->modalContent(fn() => view('modal'))
->modalCancelAction(false)
->modalSubmitAction(false)
];}
public function getFormActions(): array
{ return [ ...parent::getFormActions(),
Action::make('add example')
->modalContent(fn() => view('modal'))
->modalCancelAction(false)
->modalSubmitAction(false)
];}
<div> @livewire('add-example-modal') </div>
<div> @livewire('add-example-modal') </div>
class AddExampleModal extends Component implements HasForms, HasActions
{
public ?array $data = [];
public Test $test;
public function mount(Test $test): void
{
$this->test = $test;
$this->form->fill($test->toArray());
$testIds = session('selected_test_ids', []);
session()->forget('selected_test_ids');
}
protected function form(Form $form): Form
{
return $form
->schema([
TableRepeater::make('testes')
->headers([
Header::make(' ')->width('700px'),
])
->schema([
Select::make('test_id')
->getSearchResultsUsing(function (string $search) {
return Test::query()
\\\
});
])
->statePath('data')
->model(Test::class);
}
public function create(): void
{ $test = Test::create($this->form->getState());
$this->form->model($test)->saveRelationships(); }
public function confirmAction(): Action
{
return Action::make('confirm')
->action(function () {
$data = $this->form->getState();
session(['selected_tests' => array_column($data['tests'], 'test_id')]);
});}}
class AddExampleModal extends Component implements HasForms, HasActions
{
public ?array $data = [];
public Test $test;
public function mount(Test $test): void
{
$this->test = $test;
$this->form->fill($test->toArray());
$testIds = session('selected_test_ids', []);
session()->forget('selected_test_ids');
}
protected function form(Form $form): Form
{
return $form
->schema([
TableRepeater::make('testes')
->headers([
Header::make(' ')->width('700px'),
])
->schema([
Select::make('test_id')
->getSearchResultsUsing(function (string $search) {
return Test::query()
\\\
});
])
->statePath('data')
->model(Test::class);
}
public function create(): void
{ $test = Test::create($this->form->getState());
$this->form->model($test)->saveRelationships(); }
public function confirmAction(): Action
{
return Action::make('confirm')
->action(function () {
$data = $this->form->getState();
session(['selected_tests' => array_column($data['tests'], 'test_id')]);
});}}
0 Replies