[英]Laravel: MethodNotAllowedHttpException: The GET method is not supported for this route. Supported methods: POST
I have a very weird problem.我有一个非常奇怪的问题。 I have a post route but I receive an error that The GET method is not supported for this route.
我有一条后路由,但收到一条错误消息,指出这条路由不支持 GET 方法。
This is my web.php function:这是我的 web.php 函数:
Route::post('/sender',function () {
$text = request()->text;
event(new FormSubmitted($text));
});
I'm definitely sending a post request.我肯定会发送一个post请求。 I've already checked this: Laravel: POST method returns MethodNotAllowedHttpException
我已经检查过这个: Laravel: POST 方法返回 MethodNotAllowedHttpException
But the chosen answer is unclear.但选择的答案尚不清楚。
My View Code:我的查看代码:
<?php echo csrf_field(); ?>
{{ csrf_field() }}
<form action="/sender" method="post>
First name: <input type="text" name="fname"><br>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="content"><br>
<input type="submit">
I believe that this might just be a typo error - you have missed a quotation mark (") after 'post'我相信这可能只是一个错字错误 - 您在“发布”之后错过了引号(“)
view:看法:
<form action="/sender" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
First name: <input type="text" name="fname"><br>
<input type="text" name="content"><br>
<input type="submit">
</form>
controller控制器
Route::post('/sender',function () {
$name = request->fname;
$content = request->content
event(new FormSubmitted($name, $content));
});
EDIT: updated controller code, you were requesting the data from an input called 'text', but there wasn't any inputs with the name of 'text' in the view, only input type's编辑:更新了控制器代码,您从名为“text”的输入请求数据,但视图中没有任何名称为“text”的输入,只有输入类型
First, check you define route proper or not by php artisan route:list
command首先,通过
php artisan route:list
命令检查您是否正确定义了路由
Blade file刀片文件
<form action="{{ route('sender') }}" method="post">
@csrf
First name: <input type="text" name="fname"><br>
<input type="text" name="content"><br>
<input type="submit">
Route路线
Route::post('/sender',function () {
$text = request()->fname; //access by input field name
event(new FormSubmitted($text));
})->name('sender');
or
Route::post('/sender', 'UserController@sender')->name('sender');
if you're using route with controller then your controller seems like that如果您使用带有控制器的路由,那么您的控制器看起来就是这样
public function sender(Request $request)
{
$fname = $request->fname;
event(new FormSubmitted($fname));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.