2015-07-03 99 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引發了一個異常以避免被阻塞, –

相關問題