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')]);
});}}