Ad

Laravel - The POST Method Is Not Supported For This Route. Supported Methods: GET, HEAD

- 1 answer

I am trying to add an event on a calendar I have created, however I am getting the following error

The POST method is not supported for this route. Supported methods: GET, HEAD

I have used the methods @csrf and {{ method_field('PUT') }} to no avail. I have also cleared route cache which did not help. Any help is much appreciated.

Routes:

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', '[email protected]')->name('home');

Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function(){
    Route::middleware('can:manage-users')->group(function(){
        Route::resource('/users', 'UsersController', ['except' => ['show']]);
        Route::resource('/courses', 'CoursesController', ['except' => ['show']]);
    });
    Route::middleware('can:manage-calendar')->group(function(){
        Route::get('events', '[email protected]')->name('events.index');
        Route::post('/addEvents', '[email protected]')->name('events.add');
    });
})

index.blade.php

@extends('layouts.app')
@section ('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-14">
                <div class="card">
                        <div class="card-header">Calendar</div>
                        <div class="card-body">
                        {!! Form::open(array('route' => 'admin.events.index', 'method' => 'POST', 'files' => 'true'))!!}
                            {{-- {{method_field('PUT') }}  
                             @csrf  --}}
                        <div class="row">
                            <div class="col-xs-12 col-sm-12 col-md-12"></div>
                            <div class="col-xs-4 col-sm-4 col-md-4">
                            <div class="form-group">
                            {!! Form::label('event_name', 'Event Name:') !!}
                                <div class="">
                                    {!! Form::text('event_name', null, ['class' => 'form-control']) !!}
                                    {!! $errors->first('event_name', '<p class="alert alert-danger">:message</p>') !!}
                                </div>

@Collin, I have added the image below in relation to your question

enter image description here

Ad

Answer

Just check your form action url route. You have to pass 'route('admin.events.add)' rather than 'route('admin.events.index')' and also dont use 'PUT' it will accept 'POST' as well.

Ad
source: stackoverflow.com
Ad