简体   繁体   English

Laravel 5中的RouteCollection.php中的MethodNotAllowedHttpException

[英]MethodNotAllowedHttpException in RouteCollection.php in Laravel 5

routes.php routes.php文件

Route::get('/',array('uses'=>'student@index'));
Route::get('/view',array('uses'=>'student@view'));
Route::post('/save',array('uses'=>'student@save'));

This is the code and I am working on form and when I submit the form, it shows this error: 这是代码,我正在处理表单,当我提交表单时,它显示以下错误:

MethodNotAllowedHttpException in RouteCollection.php line 201: RouteCollection.php第201行中的MethodNotAllowedHttpException:

student.php 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 is like this: 表格是这样的:

<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>

I am stuck here. 我被困在这里。

Well, you need to configure your allowed HTTP methods in httpd.conf if you are on Apache server. 好吧,如果你在Apache服务器上,你需要在httpd.conf配置你允许的HTTP方法。

Add this line into your httpd.conf the <Directory XXXX> tag: 将此行添加到<Directory XXXX>标记的httpd.conf

AllowMethods GET POST OPTIONS
  1. You need to name the routes: see my reply here: https://stackoverflow.com/a/47147452/5550606 您需要为路线命名:请参阅我的回复: https//stackoverflow.com/a/47147452/5550606
  2. Please put the {{ csrf_field() }} right after the <form> ... tag. 请将{{csrf_field()}}放在<form> ...标记之后。 Or you will get a TokenMissmatch exception. 或者您将获得TokenMissmatch异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RouteCollection.php中的MethodNotAllowedHttpException-Laravel - MethodNotAllowedHttpException in RouteCollection.php - laravel RouteCollection.php Laravel中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php Laravel RouteCollection.php 第 219 行中的 Laravel 5 MethodNotAllowedHttpException - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel。 RouteCollection.php中的MethodNotAllowedHttpException - Laravel. MethodNotAllowedHttpException in RouteCollection.php RouteCollection.php第218行中的Laravel MethodNotAllowedHttpException: - Laravel MethodNotAllowedHttpException in RouteCollection.php line 218: Laravel 5.1中RouteCollection.php中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php in laravel 5.1 MethodNotAllowedHttpException在laravel 5中的RouteCollection.php第207行 - MethodNotAllowedHttpException RouteCollection.php line 207 in laravel 5 Laravel-RouteCollection.php第251行中的MethodNotAllowedHttpException - Laravel - MethodNotAllowedHttpException in RouteCollection.php line 251 RouteCollection.php第201行中的Laravel 5 MethodNotAllowedHttpException: - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM