Search code examples
laravelpostcontrollerget

getting errors The POST method


I have a problem with my edit page. When I submit I get this error:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

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

.

I have no clue where it comes from as I am pretty new to Laravel.

web.php

Route::post('/admin/add_reseller','ResellerController@addReseller');

Controller.php

  public function addReseller(){
         return view ('admin.resellers.add_reseller');

    }

add_reseller.blade.php

<form class="form-horizontal" method="post" action="" name="addreseller" id="addreseller">
 {{ csrf_field() }}

Solution

  • Tip:

    First of all, I would use named routes, that means you add ->name('someName') to your routes. This makes the use of routes way easier and if you decide that your url doens't fit you don't need to change it everywhere you used the route. https://laravel.com/docs/7.x/routing#named-routes

    e.g. Route::post('/admin/add_reseller',
    'ResellerController@addReseller')->name('admin.reseller');
    

    Problem:

    What I see is, that you lack the value for the action attribute in your <form>. The action is needed, so that the right route is chosen, if the form gets submitted.

    Solution:

    I guess you just have to add action="{{route('admin.reseller')}}" for the attribute, so that the request goes the right route.