laravel 细丝形式提交到线模型模型

kknvjkwl  于 2023-05-01  发布在  其他
关注(0)|答案(1)|浏览(117)

我有一个选择和datapicker细丝形式。在提交时,我想将表单中填写的数据传递给一个wire-elements模型,在表单提交时发出该模型。但是在表单提交上弹出的模态中,{{ dd($data)}}上没有显示任何内容。我做错了什么?
这就是我到现在为止所拥有的。
长丝形式组分:

class Create extends Component implements HasForms {
use InteractsWithForms;

public $data;

public function mount($office = null): void 
{
    $this->office = $office;
    $this->form->fill([
        'office_id' => $this->office,
    ]);
}

protected function getFormSchema(): array
{
    return [
        Section::make('User (Admin)')
            ->schema([
                    Select::make('user_id')
                        ->label('User')
                        ->options(User::orderBy('name')->get()->pluck('name', 'id'))
                        ->columnSpan(2)
                        ->searchable()
                        ->default(Auth::id())
                        ->disablePlaceholderSelection()
                        ->required(),
        ])->columns([
            'sm' => 1,
            'xl' => 2])
        ->hidden(Auth::user()->admin != true),

        Section::make('Date')
            ->schema([
                    DatePicker::make('date')
                        ->label('Date')
                        ->minDate(now()->startOfDay()->addDay())
                        ->displayFormat('d.m.Y')
                        ->required()
                        ->columnSpan(2),
        ])->columns([
            'sm' => 1,
            'xl' => 2]),
}

protected function getFormStatePath(): string 
{
    return 'data';
}

public function render()
{
    return view('livewire.reservations.create');
}}

成型刀片模板:

<form wire:submit.prevent='$emit("openModal", "modal.reservations", {{ json_encode(["data" => $data]) }})'>
    {{ $this->form }}

    <x-button type="submit" class="mt-4">
        Show Details
    </x-button>
</form>

模态分量:

class ReservationsShowDesks extends ModalComponent {
public $data;

public function mount($data)
{
    $this->data = $data;
}

public function close()
{
    $this->closeModal();
}

public function render()
{
    return view('livewire.modal.reservations');
}}
gtlvzcf8

gtlvzcf81#

要dd表单数据,请执行以下操作:

protected function getFormStatePath(): void
{
    dd( $this->form->getState() );
}

并在提交时从组件视图调用getFormStatePath()

<form wire:submit.prevent='getFormStatePath'>
    {{ $this->form }}

    <x-button type="submit" class="mt-4">
        Show Details
    </x-button>
</form>

相关问题