NotAllowedHttpException method 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'));

      

This is the code and I am working on a form and when I submit the form it shows this error:

Method NotAllowedHttpException on RouteCollection.php 201 line:

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');
        }

        }



      }

        }

      

The form looks 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.

+3


source to share


2 answers


Well, you need to configure the allowed HTTP methods in httpd.conf

if you are on an Apache server.

Add this line to your tag httpd.conf

<Directory XXXX>

:



AllowMethods GET POST OPTIONS

      

0


source


  • You need to provide routes: see my answer here: fooobar.com/questions/2240863 / ...
  • Place {{csrf_field ()}} right after the tag <form>

    .... Or you will get a TokenMissmatch exception.


-1


source







All Articles