Home>

I make a form system with laravel.
The following error message occurred while implementing the validation function in the form.
I would appreciate your help without knowing the cause of this error.

Error message
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message
Applicable source code

form.blade.php

{!! Form :: open (['route' =>'request/confirm', 'method' =>'post']) !!}
<div {{$errors->has ('name')? 'has-error': ''}} ">
                    <label>Participant name</label>
                        {{Form :: text ('name')}}
                    @if ($errors->has ('name'))
                        <p>{{$errors->first ('name')}}</p>
                    @endif
</div>
{!! Form :: close () !!}


ContactController.php

<? php
namespace App \ Http \ Controllers;
use Illuminate \ Http \ Request;
use Illuminate \ Support \ Facades \ Validator;

class ContactController extends Controller
{
  public function confirm (Request $request)
  {
    $this->validate ($request, [
        'name' =>'required',
    ]);
    $data = $request->all ();
    return view ('confirm')->with ($data);
  }
}
?>


web.php

Route :: get ('request/confirm', [
    'uses' =>'ContactController @ confirm',
  ]);
  Route :: post ('request/confirm', [
    'uses' =>'ContactController @ confirm',
  ]);
Supplemental information (FW/tool version etc.)

Laravel Framework 5.6.33

Reference site
  • Answer # 1

    MethodNotAllowedHttpException
    It is an error that there is no route specification around POST or GET.

    In the case of a general form flow from input screen to confirmation screen.

    If you go to the confirmation screen and validation fails, you will return to the input screen.
    Since it is a redirect, the input screen is accessed with get.

    Is the route setting on the input screen side only post?

  • Answer # 2

    Isn't it a CSRF error?
    Try {{csrf_field ()}} below the form.