Reputation: 5772
I'm quite new to Laravel and I'm facing a vague error. Whenever I try to login with an username and password, I get this error.
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
My code consists of this:
UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
class UserController extends Controller
{
public function postSignUp(Request $request){
$firstName = $request['firstName'];
$lastName = $request['lastName'];
$username = $request['username'];
$password = bcrypt($request['password']);
$email = $request['email'];
$user = new User();
$user->first_name = $firstName;
$user->last_name = $lastName;
$user->username = $username;
$user->password = $password;
$user->email = $email;
$user->save();
Auth::login($user);
return redirect()->back();
}
public function postSignIn(Request $request){
$username = $request['username'];
$password = $request['password'];
if (Auth::attempt(['username' => $username, 'password' => $password])){
return redirect()->back();
}
}
}
Provider called User.php
<?php
namespace App;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
class User extends Model implements Authenticatable
{
use \Illuminate\Auth\Authenticatable;
}
Route file web.php
<?php
Route::get('/', 'PagesController@index')->name('home');
Route::post('signup', 'UserController@postSignUp')->name('signup');
Route::get('signin', 'UserController@postSignin')->name('signin');
Upvotes: 1
Views: 1203
Reputation: 6773
It’s because the route doesn’t exist. Add the sign in post route. postSignin should be a post route
Route::post('signin', 'UserController@postSignin')->name('signin');
Route::get('signin', 'UserController@getSignin')->name('signInForm');
Instead of
Route::get('signin', 'UserController@postSignin')->name('signin’);
Upvotes: 0
Reputation: 2470
MethodNotAllowed means that you are using a VERB that the webserver didn't like for that request... i.e. GET instead of POST.
Your controller for sign-in is called postSignIn
but I notice that you are calling it with a get
Upvotes: 4