routes.php文件MethodNotAllowedHttpException在RouteCollection.php在Laravel 5
Route::get('/',array('uses'=>'[email protected]'));
Route::get('/view',array('uses'=>'[email protected]'));
Route::post('/save',array('uses'=>'[email protected]'));
這是代碼和我的工作形式,當我提交表單,它顯示了這個錯誤:
MethodNotAllowedHttpException in RouteCollection.php line 201:
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>
我被困在這裏。
您是否檢查過以確保'
啊哈! 'methed'是一個拼寫錯誤 - 應該是'method'。你的''唯一'id'裏面有空格,這是無效的。 – halfer
thankew兄弟。它的工作原理...偉大的眼睛...方法被拼錯 –