[英]MethodNotAllowedHttpException in RouteCollection.php in laravel 5.1
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 218 RouteCollection.php第218行中的MethodNotAllowedHttpException
Here is my code: 这是我的代码:
UserController.php 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 routes.php
<?php
Route::get('/', function () {
return view('welcome');
});
Route::post('/signup',[
'uses' => 'UserController@postSignUp',
'as' => 'signup'
]);
welcome.blade.php 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
Please note that I am working on laravel 5.1 & I am a beginner. 请注意,我正在研究laravel 5.1,我是初学者。 Can you please help me to solve the problem? 您能帮我解决问题吗?
You have a typo in your form: 您的输入有错字:
mathod="post"
...change to: ...改成:
method="post"
Since the form don't actually get a method defined, it uses get
as default. 由于表单实际上并未定义方法,因此它默认使用get
。
<form action="{{ route('signup')}}" mathod="post">
You have error over here. 您在这里有错误。 It should be: 它应该是:
<form action="{{ route('signup')}}" method="post">
from mathod to method 从方法到方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.