RouteCollection.php第218行中的Laravel MethodNotAllowedHttpException:

时间:2016-10-30 22:49:47

标签: php laravel

我是laravel的新手,当我遇到这个问题时,我试图从youtube教程中学习。我有一个注册表单并在提交时我发布表单数据并尝试将其保存在我的用户表中,但是当我在RouteCollection.php第218行收到此异常时,我发现这个异常:我会很感激任何有助于解决此错误的帮助。下面是我的代码

我的控制器

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User;
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();

    }
    public function postSignIn(Request $request)
    {

    }
}

我的路由器

Route::get('/', function () {
    return view('welcome');
});
Route::post('/signup', [
    'uses'=>'UserController@postSignUp',
    'as'=>'signup'
]);

我的表格

    <form action="{{route('signup')}}" meathod="post">
         <div class="form-group">
             <label for="email">Email</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email">
         </div>  
         <div class="form-group">
             <label for="firstname">First Name</label>
             <input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name">
         </div>  
         <div class="form-group">
            <label for="password">Password</label>
             <input type="password" class="form-control" id="password" name="password" placeholder="passwprd">
         </div>  
         <div class="form-group">
        <button type="submit" class="btn btn-primary">Sign up</button>

         </div>
       <input type="hidden" name="_token" value="{{Session::token()}}">
</form>

2 个答案:

答案 0 :(得分:0)

检查您的打开的<form>代码。

meathod="post"

应该是

method="post"

您有拼写错误,因此表单会以GET而非预期的POST发布。

无关,我建议使用更简单的CSRF输入形式

{{ csrf_field() }}

而不是

<input type="hidden" name="_token" value="{{Session::token()}}">

答案 1 :(得分:0)

     <form action="{{route('signup')}}" method="post">
{{ csrf_field() }}
             <div class="form-group">
                 <label for="email">Email</label>
                <input type="email" class="form-control" id="email" name="email" placeholder="Email">
             </div>  
             <div class="form-group">
                 <label for="firstname">First Name</label>
                 <input type="text" class="form-control" id="first_name" name="first_name" placeholder="First Name">
             </div>  
             <div class="form-group">
                <label for="password">Password</label>
                 <input type="password" class="form-control" id="password" name="password" placeholder="passwprd">
             </div>  
             <div class="form-group">
            <button type="submit" class="btn btn-primary">Sign up</button>

             </div>
           <input type="hidden" name="_token" value="{{Session::token()}}">
    </form>