在laravel 5.1中的RouteCollection.php中的MethodNotAllowedHttpException

时间:2016-10-11 14:48:59

标签: php routes laravel-5.1

这是代码,我正在处理表单,当我提交表单时,它会显示以下错误:

RouteCollection.php第218行中的MethodNotAllowedHttpException

这是我的代码:

UserController.php

    <?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
    public function postSignUp(Request $request){

        $email=$request['email'];
        $first_name=$request['first_name'];
        $password=bcrypt($request['password']);

        $user= new User();
        $user->email=$email;
        $user->first_name=$first_name;
        $user->password=$password;

        $user->save();
        return redirect()->back();

    }


}

routes.php文件

<?php


Route::get('/', function () {
    return view('welcome');
});

Route::post('/signup',[
        'uses' => 'UserController@postSignUp',
        'as' => 'signup'
    ]);

welcome.blade.php

@extends('layouts.master')

@section('title')
    Welcome!
@endsection

@section('content')
    <div class="row">
        <div class="col-md-6">
            <h3>Sign Up</h3>
            <form action="{{ route('signup')}}" mathod="post">
                <div class="form-group">
                   <label for="email">Email</label> 
                  <input type="email" class="form-control" name="email">
                </div>

                <div class="form-group">
                   <label for="first_name">Your First Name</label>  
                  <input type="text" class="form-control" name="first_name">
                </div>

                <div class="form-group">
                   <label for="password">Password</label>   
                  <input type="password" class="form-control" name="password">
                </div>
                <button type="submit" class="btn btn-primary">Submit</button>
                <input type="hidden" name="_token" value="{{ Session::token() }}">
            </form>

        </div>



    </div>
@endsection

请注意我正在开发laravel 5.1&amp;我是初学者。你能帮我解决一下这个问题吗?

2 个答案:

答案 0 :(得分:2)

您的表单中有拼写错误:

mathod="post"

...改为:

method="post"

由于表单实际上未定义方法,因此默认使用get

答案 1 :(得分:1)

    <form action="{{ route('signup')}}" mathod="post">

你在这里有错误。 它应该是:

    <form action="{{ route('signup')}}" method="post">

从mathod到方法