在Laravel中创建一个表单

I am beginner in Laravel. I use in my project. Laravel 7 and https://www.bgaze.fr/bootstrap-form#forms.

我有这个表格:

<form method="POST"
                          @if($page ?? '' ?? false) action="{{ route('page.update', ['id' => $page->id ?? null]) }}"
                          @else action="{{ route('page.store') }}" @endif class="form form-horizontal form-bordered">
                        @if($page ?? '' ?? false) @method('PUT') @endif
                        {{ csrf_field()  }}

                        <div class="box-body">
                            <div class="form-group">
                                <label for="title">Tytuł strony tekstowej*</label>
                                <input id="title" type="text" name="title" required="required" maxlength="155"
                                       class="form-control"
                                       placeholder="Wpisz tytuł strony tekstowej*" value="{{ $page->title ?? old('title') }}">
                            </div>

                            <div class="form-group">
                                <label for="description">Description</label>
                                <input id="description" type="text" name="description" maxlength="155"
                                       class="form-control"
                                       placeholder="Wpisz description" value="{{ $page->description ?? old('description') }}">
                            </div>

                            <div class="form-group">
                                <label for="exampleInputEmail1">Keywords</label>
                                <input id="keywords" type="text" name="keywords" maxlength="155" class="form-control"
                                       placeholder="Wpisz keywords" value="{{ $page->keywords ?? old('keywords') }}">
                            </div>

                            <div class="form-group">
                                <label for="exampleInputEmail1">Treść strony tekstowej</label>
                                <textarea class="form-control summernote" name="content" rows="3"
                                          placeholder="Wpisz treść strony tekstowej">{{ $page->content ?? old('content') }}</textarea>
                            </div>

                            <div class="form-group size-200">
                                <label for="exampleInputEmail1">Wpis aktywny</label>
                                <label class="switch ">
                                    <input name="enable" value="1"
                                           @if(!empty($page) && $page->enable == '1') checked="checked"
                                           @endif  type="checkbox" class="primary" id="switch1"/>
                                    <span class="switcher round"></span>
                                </label>
                            </div>


                            <div class="box-footer">
                                <button type="submit"
                                        class="btn btn-primary">Zapisz</button>
                            </div>

                        </div>

                    </form>

我正在尝试以引导程序形式编写它:

@open(['store' => ['page.store'], 'update' => ['page.update', ['id' => $page->id ?? '']], 'method' => 'POST', 'class' => 'users-search-form', 'novalidate' => env('FORM_VALIDATE')])
                    @text('title', 'Tytuł strony tekstowej*', $page->title ?? old('title'), ['id'=>'id', 'class'=>'form-control', 'required'=>true, 'placeholder'=>'Wpisz tytuł strony', 'maxlength'=>155])
                    @text('description', 'Description', $page->description ?? old('description'), ['id'=>'id', 'class'=>'form-control', 'placeholder'=>'Wpisz description strony', 'maxlength'=>155])
                    @text('keywords', 'Keywords', $page->keywords ?? old('keywords'), ['id'=>'id', 'class'=>'form-control', 'placeholder'=>'Wpisz keywords strony', 'maxlength'=>155])
                    @textarea('content', 'Treść strony', $page->content ?? old('content'), ['id'=>'id', 'class'=>'form-control summernote'])

                    @checkbox('name', 'Wpis aktywny', 1, ($page->enable == 1 ? true : false) ?? '', ['switch' => true, 'inline' => true, 'group' => true])
                    @submit('Zapisz')
                    @close

我有一些疑问和问题: 1.我的表单URL始终是页面/创建。 -不是page.store(在创建新页面时)或page.update(在编辑时) 2.我想要POST方法用于page.save,PUT用于更新(page.update) 3.通常,我的代码正确吗? $ page-> id ?? '' - 是必须的?

评论