artisticre's avatar

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

My Form

<section id="contact">
    
        <div class="container text-center">
            @if (Session::has('flash_message'))
        <div class="alert alert-primary" role="alert">
            This is a primary alert—check it out!
          </div>
 @endif
          <div class="row">
            <div class="col-12 m-t-75">
              <h1 class="abouttitle">Contact Us</h1>
               
            </div>
          </div>
          <div class="row m-t-30">
            <div class="col">
                <form action="{{url('/#contact')}}" method="PUT" role="form">
                    {{csrf_field()}}
                   <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <input type="text" name="name" class="form-control" placeholder="Your Name *" value="" />
                                @if ($errors->has('name'))
                      <p class="help is-danger">{{$errors->first('name')}}</p>
                      @endif
                              </div>
                              
                            <div class="form-group">
                                <input type="text" name="email" class="form-control" placeholder="Your Email *" value="" />
                            </div>
                            <div class="form-group">
                                <input type="text" name="phone" class="form-control" placeholder="Your Phone Number *" value="" />
                            </div>
                            <div class="form-group">
                                <input type="submit" name="submit" class="btnContact" value="Send Message" />
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <textarea name="message" class="form-control" placeholder="Your Message *" style="width: 100%; height: 150px;"></textarea>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
            
          </div>
        </div>
        
        </section>
        

My Routes

Route::get('/#contact', 'ContactController@getContact');
Route::get('/#contact', 'ContactController@postContact');

My Controller

public function getContact()
    {
      return view('/#contact');
    }

    public function postContact(Request $request)
            {
            $this->validate($request, [
              'name' => 'required',
              'email' => 'required|email',
              'phone' => 'required',
              'message' => 'required'
            ]);
              $data = array(
                  'name' => $request->name,
                  'email' => $request->email,
                  'phone' => $request->phone,
                  'subject' => $request->subject,
                  'msg' => $request->message 
              );
            
            
            Mail::send('emails.contact', $data, function($message) use ($data) {
                $message->from($data['email']);
                $message->to('[email protected]');
                $message->subject($data['subject']);
            });
            Session::flash('success', 'Your Email was Sent!');

            return redirect('/#contact');
        }
0 likes
10 replies
ashkan90's avatar

you cannot set form method to put directly.

try this,

<form method="post" action="...">
    @method('put') 
    ....
    ....
</form>

Also as @snapey said, you should change the second one's method

Snapey's avatar

er

Route::get('/#contact', 'ContactController@getContact');
Route::get('/#contact', 'ContactController@postContact');

both get?

Try changing the second

Route::get('/#contact', 'ContactController@getContact');
Route::post('/#contact', 'ContactController@postContact');
Snapey's avatar

both answers are valid. If you want to use PUT (because you are changing an existing record) then you need to set the method to POST, add the hidden method field as PUT and change the route

Route::get('/#contact', 'ContactController@getContact');
Route::PUT('/#contact', 'ContactController@postContact');
artisticre's avatar

Sorry I forgot I changed the Route Yes my routes are like these and it still does not work

Route::get('/#contact', 'ContactController@getContact');
Route::post('/#contact', 'ContactController@postContact');
uksarkar's avatar

Hello @artisticre in your form you type the wrong method,

your wrong form method is,

<form action="{{url('/#contact')}}" method="PUT" role="form">
.......
</form>

Change this to

<form action="{{url('/#contact')}}" method="post" role="form">
..........
</form>

Your route should be,

Route::get('/#contact', 'ContactController@getContact');
Route::post('/#contact', 'ContactController@postContact');

And if you need a put request then you can type @method("PUT") in this form, and also take care of your Route.

artisticre's avatar

I changed everything as below and it still gives me the post error:

Route::get('/#contact', 'ContactController@getContact');
Route::post('/#contact', 'ContactController@postContact');

And my form to

                <form action="{{url('/#contact')}}" method="post" role="form">
Snapey's avatar

and you did not add the method

 @method('put')
Snapey's avatar

Im checking that you have NOT added it because it was suggested earlier

uksarkar's avatar
uksarkar
Best Answer
Level 2

Hey @artisticre Your error is occurring because of the # on your route. The browser always sent the request to the base url. You should remove the # from your route.

Make your route like this

Route::get('/contact', 'ContactController@getContact');
Route::post('/contact', 'ContactController@postContact');

And form like this

<form action="{{url('/contact')}}" method="post" role="form">

It will solve the problem.

2 likes

Please or to participate in this conversation.