php - 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 令牌,但数据从未发送到数据库,尽管一切似乎都正确。
解决方案
路由方法配置问题将发生 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.
没有其他解决方案。
推荐阅读
- google-apps-script - Apps Script Bot 上的 404 截断服务器响应
- r - 创建比旧数据框更大的新数据框
- jquery - 从 jquery ajax 调用 API 控制器 ASP.net Core 时出现错误的请求错误
- reactjs - React - 条件渲染不清除输入值
- javascript - 提交和取消按钮不起作用,并且弹出窗口会导致可折叠面板关闭。我们如何解决这个问题?
- go - 短格式 goroutine 返回值
- vb.net - vb.net 在 TabControl 中查找以指定字符串开头的文本框名称
- ios - 尝试将 UILabel 设置为 UISegmentedControl 项时遇到类型问题
- python - 数据框中的 Groupby 并将完整行列表传递给缩减函数
- responsive-design - 使用 bootstrap-vue 不会自动滚动