2015-07-03 104 views
3

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> 

我被困在这里。

+0

您是否检查过以确保'

'是使用'/ save'路径呈现的?你检查过路线文件的确是运行?也许它是在错误的地方。 – halfer

+7

啊哈! 'methed'是一个拼写错误 - 应该是'method'。你的''唯一'id'里面有空格,这是无效的。 – halfer

+0

thankew兄弟。它的工作原理...伟大的眼睛...方法被拼错 –

回答

0

那么,如果您在Apache服务器上,则需要在httpd.conf中配置允许的HTTP方法。

添加此行到您的httpd.conf的​​标签:

AllowMethods GET POST OPTIONS 
+0

你能多解释一下吗? –

+0

嗯,这是服务器发送给你的laravel应用程序的一种错误,所以Laravel引发了一个异常以避免被阻塞, –

相关问题