Sekhon Sekhon - 1 month ago 11
PHP Question

Laravel MethodNotAllowedHttpException in RouteCollection.php line 218:

I am new to laravel and I was trying to learn from a youtube tutorial when i faced this problem. I have a signup form and on submit I am posting the form data and trying to save it in my user table but thats when i have recieved this exception MethodNotAllowedHttpException in RouteCollection.php line 218:.I would appreciate any help to solve this error. below is my code

My controller

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

}
}


my Router

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


MY form

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

Answer

Check your open <form> tag.

meathod="post"

should be

method="post"

You have a typo, so the form is posting as a GET instead of the intended POST.


Unrelated, I suggest using the simpler form of the CSRF input

{{ csrf_field() }}

instead of

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