首页 > 解决方案 > Laravel:表单提交时不显示错误消息

问题描述

路线定义:

Route::get('/sign_up','NavigationController@show_sign_up');
Route::post('/sign_up','DatainsertController@sign_up_data');

控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\sender;

class DatainsertController extends Controller
{
    public function sign_up_data(Request $request)
    {  

        //create a new post using the request data 
        $post=new post;
        $post->first_name=$request('first_name');
        $post->last_name=$request('last_name');

        //save to the database 

        $post->save();

        //the redirect to the home page 

        return redirect('/');

    }
}

这是我看到的错误消息: 这是错误信息

我在路由上使用了 post 方法,并在表单中使用了 CSRF 令牌,但数据从未发送到数据库,尽管一切似乎都正确。

标签: phpmysqllaravel

解决方案


路由方法配置问题将发生 Method Not Allowed 异常。

首先检查您的路线,(web.php)

Route::get('/sign_up','NavigationController@show_sign_up')->name('getsignup');

Route::post('/sign_up','DatainsertController@sign_up_data')->name('postsignup');

去你的视野,

打开开发工具,看看你的浏览器是否真的在做 POST 而不是 GET

也尝试将 action="/fproject/public/sign_up" 更改为 action="{{ route('postsignup') }}"

转到控制器

Add namespace like `App\Post` or whatever required.

没有其他解决方案。


推荐阅读