laravel中的post方法给出MethodNotAllowedHttpException [英] post method in laravel give MethodNotAllowedHttpException

查看:489
本文介绍了laravel中的post方法给出MethodNotAllowedHttpException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Laravel中的post方法给出MethodNotAllowedHttpException

post method in Laravel give MethodNotAllowedHttpException

HTML代码

<form action="newslatter" method="post">
<input type="text" name="name">
    <br>
    <br>
<input type="email"name="email">
<br>
<br>
<input type="submit">

和控制器代码

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class newsletter extends Controller
{
public function store(Request $request)
{
 return $request -> name .'   '. $request -> email;
}

和路线

Route::POST('Newslatter','newsletter@store');

我的代码有什么问题?

错误图片

推荐答案

在路由中将Newslatter更改为newslatter使其起作用:

Change Newslatter to newslatter in the route to make it work:

Route::post('newslatter', 'newsletter@store');

还要在表单中添加 CSRF字段:

<form action="newslatter" method="post">
    {{ csrf_field() }}

Laravel 5.6+ 中:

<form action="newslatter" method="post">
    @csrf

这篇关于laravel中的post方法给出MethodNotAllowedHttpException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆