MethodNotAllowedHttpException in RouteCollection.php in Lara


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中的MethodNotAllowedHttpException第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>

我被困在这里了。

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

将这一行添加到您的httpd.conf <Directory XXXX>标签:

AllowMethods GET POST OPTIONS
  1. 您需要命名路线:请参阅我的回复:https://stackoverflow.com/a/47147452/5550606
  2. 请将{{csrf_field((}}放在<form>之后。。。标签或者您将得到一个TokenMissmatch异常