Manish
Manish

Reputation: 13

MethodNotAllowedHttpException for Post Method .Get and Head Supported

I defined my route in web.php as Post method. and csrf token is also added in form . Route:list command is working perfect and showing that post route. but when I submit form it shows The POST method is not supported for this route. Supported methods: GET, HEAD.

@csrf added to form tag. php artisan route:list working properly showing that defined post route.

   <form method="POST" method="plantouser">
              @csrf
              <h1>Select Plan</h1>
              <div>
                <select name="plans" class="form-control">
                  @foreach($plan as $plan)
                  <option value="{{$plan->planamount}}">{{$plan->planname}} of {{ $plan->planamount}}</option>
                  @endforeach
                </select>
              </div>
              <div class="clearfix"></div>
              <div class="separator">
                <button type="submit">Submit</button>
              </div>
            </form>

Route::post('/plantouser','PlanController@planToUser');

public function planToUser(Request $request){

    $payment=Planpaymentdetail::create([
            'paymenttype'=>'online',
            'pyamount'=>$price,
            'pycoinamount'=>$dec['result']['amount'],
            'pytxnhash'=>$dec['result']['txn_id'],
            'pyinitiatetime'=>now(),
        ]);
    return redirect()->back()->with('success','Plan selected successfully');
}

this image showing data which is post by form to server

Expected Result is to redirect to url with message but getting MethodNotAllowedHttpException The POST method is not supported for this route. Supported methods: GET, HEAD.

Upvotes: 1

Views: 137

Answers (2)

zahid hasan emon
zahid hasan emon

Reputation: 6233

It should be like this:

<form method="POST" action="{{ url('plantouser') }}">

Upvotes: 0

Jerodev
Jerodev

Reputation: 33186

The URL you post to should be set with the action attribute of your form tag, not the method attribute:

<form method="POST" action="/plantouser">

Upvotes: 1

Related Questions