簡體   English   中英

此路由不支持 POST 方法 laravel 7

[英]The POST method is not supported for this route laravel 7

我正在准備創建表單來創建事件。

我的 laravel 7 中有一個 resourceRoute。但是當我發送表單時,返回此消息:

此路由不支持 POST 方法

但我怎么說我有一個資源路線,我調用方法創建。

我的路線 Route::resource('calendario', 'CalendarioController');

我的表格:

div class="col-xs-12 p-5">
                <form action="{{ Request::is('calendario/*/edit') ? route('calendario.update', $event->id) : route('calendario.create') }}" method="post">
                    @csrf
                    
                    @if(Route::currentRouteName() == 'calendario.edit')
                        @method('PUT') 
                    @endif

                    <div class="form-group">
                        <label for="nombre">Nombre</label>
                        <input type="text" class="form-control" name="nombre" id="nombre" value="{{ isset($event) ? $event->nombre : old('nombre') }}" aria-describedby="emailHelp" placeholder="Nombre del cliente">
                    </div>
                    <div class="form-group">
                        <label for="fecha-inicio">Fecha Inicio</label>
                        <input type="text" value="{{ isset($event) ? $event->fecha_inicio : old('fecha_inicio') }}" class="form-control" name="fecha_inicio" id="fecha-inicio">
                    </div>
                    <div class="form-group">
                        <label for="fecha-inicio">Fecha Fin</label>
                        <input type="text" value="{{ isset($event) ? $event->fecha_fin : old('fecha_fin') }}" class="form-control" name="fecha_fin" id="fecha-fin">
                    </div>
                    <input type="submit" class="btn btn-info" value="{{ Request::is('calendario/*/edit')  ? 'Guardar' : 'Crear Cita' }}">
                </form>
            </div>
        </div>
    </div>

這種形式也用於編輯事件,在編輯中我可以...我不明白我做錯了

謝謝你的幫助

這是Route::resource('calendario', 'CalendarioController') 100% 的問題

我記得更新方法接受put

正如你在這里看到的:put/patch

因此,您可以將表單方法更改為method="put"或者您必須像這樣定義您的路線: Route::post('path/{id}', 'CalendarioController@update')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM