1

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');
1

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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’);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.