【发布时间】:2017-11-07 07:27:24
【问题描述】:
routes.php
Route::get('/',array('uses'=>'student@index'));
Route::get('/view',array('uses'=>'student@view'));
Route::post('/save',array('uses'=>'student@save'));
这是代码,我正在处理表单,当我提交表单时,它显示此错误:
RouteCollection.php 第 201 行中的 MethodNotAllowedHttpException:
student.php
class student extends Controller {
public function index()
{
//return 'hello world';
return \View::make('student.index');
}
public function view()
{
return \View::make('student.view');
}
public function save()
{
//return \View::make('student.view');
$validation= array(
'first_name'=>'required',
'email'=>'required'
);
$v1=validator::make(Input::all(),$validation);
if( $v1->fails())
{
return Redirect::to('view')->withErrors($v1);
}
else
{ $poststudent=Input::all();
$data = array('first_name'=>$poststudent['first_name'],
'last_name'=>$poststudent['last_name'],
'email'=>$poststudent['email'],
'interested'=>$poststudent['interested'],
'skills'=>$poststudent['skills']);
$check=0;
$check=DB::table('students')->insert($data);
if($check > 0)
{
return Redirect::to('/');
}
else
{
return Redirect::to('/view');
}
}
}
}
表格是这样的:
<form action="<?=URL::to('/save')?>" methed="POST">
<div class="form-group">
<label for= "first_name"> FIRST NAME </label>
<input name="FIRST NAME" type="text" value="" class="form-control" id="first name"/>
</div>
我被困在这里了。
【问题讨论】:
-
您是否检查过以确保
<form>是使用/save路由呈现的?你检查过路由文件确实运行了吗?可能是放错地方了。 -
啊哈!
methed是一个拼写错误 - 应该是method。此外,您的<input />唯一id中有空格,这是无效的。 -
谢谢兄弟。它的工作...伟大的眼睛...方法拼错了
-
如果你没有使用 Laravel 的表单构建器,你必须自己包含 CSRF 令牌。请参阅 Laracasts 上的此条目
-
确保你的控制器中有
useInput外观。将use Illuminate\Support\Facades\Input;放在控制器的顶部。