1
votes

I am getting the "MethodNotAllowedHttpException" error on form submit, but I can't figure out why. Here is my form, created with Laravel Collective form creator:

{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}

    //Bunch of Form Inputs here:

    {!!Form::submit('Create Listing')!!}
    {!! Form::close() !!}

Then here is my route:

Route::post('photographer/listing/store', 'PhotographerController@storeListing');

And Finally, here is the controller:

    class PhotographerController extends Controller
{
        public function storeListing(Request $request)
          {


            //Form Validation

            //Store in the database

            return redirect('/photographer');

          }

}

From what I have seen, this error comes up when you use the incorrect method for the request, ex. route is a get where form is a post, but that isn't the case here, so I don't really know what is going on.

Update: I am also including the relevant information from php artisan route:list as well here:

 POST     | photographer/listing/store     |                           | App\Http\Controllers\PhotographerController@storeListing               | web,auth:photographer  
GET|HEAD | photographer                   | photographer.dashboard    | App\Http\Controllers\PhotographerController@index                      | web,auth:photographer 
1
Try setting absolute url in your form. Like this ['url' => '/photographer/listing/store' ...]. I'd even suggest you to name your routes and call them with route(name). - DevK
Tried that already, didn't work. - Eric Brown
try using url helper: 'url' => url( 'photographer/listing/store') - Peyman
@PeymanSeraj Thanks for the tip, but that didn't work either. - Eric Brown
Please try to list your routes. php artisan route:list . can you see your route? - Peyman

1 Answers

0
votes

Have you checked where that the URL on the form action is correct?

My guess is that the following line:

{!! Form::open(['url' => 'photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}

isn't pointing to the relative URL you expect. Try adding in the forward slash in the url parameter as below:

{!! Form::open(['url' => '/photographer/listing/store', 'method'=>'POST', 'files' => true]) !!}