简体   繁体   English

此路由不支持 POST 方法。 支持的方法:GET、HEAD In Laravel

[英]The POST method is not supported for this route. Supported methods: GET, HEAD In Laravel

When i click on send button i got this error message: "The POST method is not supported for this route. Supported methods: GET, HEAD."当我单击发送按钮时,我收到此错误消息:“此路由不支持 POST 方法。支持的方法:GET、HEAD。”

My view:我的观点:

<form action="" method="post">

@csrf
<h1> Gmail Sender </h1>

        <div class='form-group'>
            <label>Email:</label>
            <div class="form-group col-md-3">
                <input name="email" type="email" placeholder= "Email to .."/>
          </div>
        </div>

        <div class='form-group'>
            <label>Subject:</label>
            <div class="form-group col-md-3">
                <input name="subject" type="subject" placeholder= "Email to .."/>
          </div>
        </div>

          <div class='form-group'>
            <label>Content:</label>
            <div class="form-group col-md-4">
            <textarea  class="form-control" name="txtDescription"
             id="txtDescription" cols="30" rows="3" ></textarea>
          </div>
          </div>

          <button> SEND</button>

        </div>
    </div>
</div>
</div>
 @endsection

My controller:我的 controller:

<?php
namespace App\Http\Controllers;
use\Illuminate\Support\Facades\Mail;
use Illuminate\Http\Request;
use App\Mail\MyMail;

class MyMailController extends Controller
{
public function sendMail(Request $request){
$this->validate($request,[
'email'=>'required',
'subject'=>'required',
'content'=>'required',
]);

   $myMail= new MyMail(
      $request->input('subject'),
    $request->input('content')
    );

   Mail::to($request->input('email'))->send($myMail);
   return redirect()->back()->with('success', 'Email sent successfully. to:' .$request->input('email'));
}
}

my route:我的路线:

Route::view('/sendmail', 'sendmail');
Route::post('/' , 'MyMailController@sendMail');

I want to send email.我想发送 email。 But when I click on send button, I got this error message "The POST method is not supported for this route. Supported methods: GET, HEAD."但是当我单击发送按钮时,我收到此错误消息“此路由不支持 POST 方法。支持的方法:GET、HEAD。”

I use a named route for a better management in form action.我使用命名路由来更好地管理表单操作。

Route::post('/' , 'MyMailController@sendMail')->name('sendMail');

In your view dont forget to add action to your form在您看来,不要忘记在表单中添加操作

<form action="{{ route('sendMail') }}" method="post">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Laravel - 此路由不支持 POST 方法。 支持的方法:GET、HEAD - Laravel - The POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 POST 方法。 支持的方法:GET、HEAD (LARAVEL) - POST method is not supported for this route. Supported methods: GET, HEAD (LARAVEL) 错误:此路由不支持 POST 方法。 支持的方法:GET、HEAD - Error:The POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 POST 方法。 支持的方法:GET、HEAD - POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 POST 方法。 支持的方法:GET、HEAD - The POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 POST 方法。 支持的方法:GET、HEAD、PUT - The POST method is not supported for this route. Supported methods: GET, HEAD, PUT LARAVEL 9 此路由不支持 PUT 方法。 支持的方法:GET、HEAD - LARAVEL 9 The PUT method is not supported for this route. Supported methods: GET, HEAD laravel 8 模块形式错误 此路由不支持 POST 方法。 支持的方法:GET、HEAD - laravel 8 module form error The POST method is not supported for this route. Supported methods: GET, HEAD 在 Laravel 中,我遇到错误此路由不支持 POST 方法。 支持的方法:GET、HEAD - in Laravel I GOT AN ERROR The POST method is not supported for this route. Supported methods: GET, HEAD 此路由不支持 DELETE 方法。 支持的方法:GET、HEAD、POST。 在 laravel - The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST. in laravel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM