1
votes

I´m traying to create form to create event.

i have one resourceRoute in my laravel 7. But when i send my form, return this message:

The POST method is not supported for this route

but how i said i have a resource route, and i call to method create.

My routes Route::resource('calendario', 'CalendarioController');

My form:

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>

thsi form it´s used also for edit event and in edit i can ok... I don´t understand that i´m doing wrong

Thanks you for help

1

1 Answers

0
votes

This is 100% an issue with the Route::resource('calendario', 'CalendarioController')

The update method accepts put as I can remember.

As you can see here: put/patch

So you can change your form method to method="put" or your have to define your routes like this: Route::post('path/{id}', 'CalendarioController@update')