【发布时间】:2016-06-15 01:58:57
【问题描述】:
首先我的错误是找不到类输入所以我添加了
'Input' => Illuminate\Support\Facades\Input::class,
在别名数组中
现在当我提交我的表单时,它给出了这个错误
错误:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException:
Routes.php
Route::post('add', function () {
$name = Input::get('name');
if(DB::table('projects')->whereName($name)->first() != NULL) return 'already exist';
DB::table('projects')->insert(array('name'=>'$name'));
return Redirect::to('/add');
});
welcome.blade.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel Learning</title>
</head>
<body>
{!! Form::open(array('url' => 'add')) !!}
{!! Form::text('name', 'Your Name...') !!}
{!! Form::submit('Click Me!') !!}
{!! Form::close() !!}
</body>
</html>
【问题讨论】:
-
数据是否被插入?由于您还重定向到
return Redirect::to('/add');,这将是一个GETurl。 -
同时传递 csrf_token
-
@Ciccio nopx 我只看到了那个错误,没有任何东西插入到数据库中!
-
@aldrin27 是必须的吗?
-
来自文档
If you use the Form::open method with POST, PUT or DELETE the CSRF token will be added to your forms as a hidden field automatically.,所以如果您检查页面源(在浏览器中),我怀疑它已经存在了。
标签: php forms laravel-5.2