artisticre
1 month ago
91
10
Laravel

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

Posted 1 month ago by artisticre

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', '[email protected]');
Route::get('/#contact', '[email protected]');

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');
        }

Please sign in or create an account to participate in this conversation.