0

I have following the official guide to upgrade from laravel 5.2 to laravel 5.3: https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0

Because I needed some customizations to the default authentication I have copied the login function to Http\Controllers\Auth\AuthController.php.

Now, when I updated, the `AuthController.php' was divided into several other files.

I have copied the login function to Http\Controllers\Auth\LoginController.php

Now, I am getting the following error when trying to login:

BadMethodCallException in Controller.php line 82:

Method [getCredentials] does not exist.

The login functions below (Might not matter):

public function login(Request $request) { $this->validate($request, [ 'email' => 'required|email', 'password' => 'required', ]); $credentials = $this->getCredentials($request); // This section is the only change if (Auth::validate($credentials)) { $user = Auth::getLastAttempted(); if ($user->active) { Auth::login($user, $request->has('remember')); ActivityLog::add("User has successfully logged in.", $user->id); return redirect()->intended($this->redirectPath()); } else { return redirect($this->loginPath) // Change this to redirect elsewhere ->withInput($request->only('email', 'remember')) ->withErrors([ 'active' => 'This account has been suspended.' ]); } } return redirect($this->loginPath) ->withInput($request->only('email', 'remember')) ->withErrors([ 'email' => $this->getFailedLoginMessage(), ]); } 

How do I fix this?

3
  • Where is the getCredentials method? It says it can't find it Commented Feb 27, 2017 at 12:00
  • Well, probably this method was removed between 5.2 and 5.3. Or replaced with something else... Commented Feb 27, 2017 at 12:03
  • So you didn't create it? Because the error clearly states that your code requires it, and you're using it here $credentials = $this->getCredentials($request); Commented Feb 27, 2017 at 12:04

2 Answers 2

4

This method simply returns the login username (which can be username, email or custom field) and the password from the request data. You can replace the getCredentials() call with this:

$request->only($this->username(), 'password'); 

NOTE

depending on how you merged the code, the method $this->username() can be also used as $this->loginUsername() in the older version.

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

1 Comment

Method [loginUsername] does not exist. the method with $this->username() did the trick! Thanks!
1

Anyone else looking here now the call getCredentials(Response $response) was replaced in 5.3 with credentials(Response $response)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.