簡體   English   中英

Laravel 5中的RouteCollection.php中的MethodNotAllowedHttpException

[英]MethodNotAllowedHttpException in RouteCollection.php in Laravel 5

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>

我被困在這里。

好吧,如果你在Apache服務器上,你需要在httpd.conf配置你允許的HTTP方法。

將此行添加到<Directory XXXX>標記的httpd.conf

AllowMethods GET POST OPTIONS
  1. 您需要為路線命名:請參閱我的回復: https//stackoverflow.com/a/47147452/5550606
  2. 請將{{csrf_field()}}放在<form> ...標記之后。 或者您將獲得TokenMissmatch異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM