ERROR: Declaration of App\Services\CustomPasswordBroker

Posted by

Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Error:

Declaration of App\Services\CustomPasswordBroker::sendResetLink(array $credentials, ?Illuminate\Http\Request $request = null) must be compatible with Illuminate\Auth\Passwords\PasswordBroker::sendResetLink(array $credentials, ?Closure $callback = null) {"exception":"[object] (Symfony\\Component\\ErrorHandler\\Error\\FatalError(code: 0): Declaration of App\\Services\\CustomPasswordBroker::sendResetLink(array $credentials, ?Illuminate\\Http\\Request $request = null) must be compatible with Illuminate\\Auth\\Passwords\\PasswordBroker::sendResetLink(array $credentials, ?Closure $callback = null) at /opt/lampp/htdocs/devopsschool/ds-student-ms/app/Services/CustomPasswordBroker.php:18)
[stacktrace]
#0 {main}

Solution:

Step – 1 – Go to your Laravel 10 project.

Step – 2 – find the file named CustomPasswordBroker.php which is usually present in the \app\Services\CustomPasswordBroker.php.

Step – 3 – The Illuminate\Auth\Passwords\ basic classThe sendResetLink method in PasswordBroker has the following signature:

Replace your code from this:

public function sendResetLink(array $credentials, Request $request = NULL)
to this Code:

public function sendResetLink(array $credentials, $callback = NULL)

Step – 4 – And Replace the $request code from $callback in your whole file.

Step – 5 – As you can see my whole updated code below:

use Illuminate\Auth\Passwords\PasswordBroker as BasePasswordBroker;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;

class CustomPasswordBroker extends BasePasswordBroker    
{    
@@ -15,12 +14,12 @@ class CustomPasswordBroker extends BasePasswordBroker
     * @param  array  $credentials
     * @return string
     */
    public function sendResetLink(array $credentials, Request $request = NULL)
    public function sendResetLink(array $credentials, $callback = NULL)
    {
    	Log::info('--- Inside CustomPasswordBroker->sendResetLink() ---');
    	$case = '';
    	if($request !== NULL && $request->get('case') != "") {
    		$case = $request->get('case');
    	if($callback !== NULL && $callback->get('case') != "") {
    		$case = $callback->get('case');
    	}

        Log::info('--- Inside CustomPasswordBroker->sendResetLink() ---');
        
        $user = $this->getUser($credentials);
        if (is_null($user)) {
            return static::INVALID_USER;
        }
       
        Log::info('$case: ' . $case);
        switch ($case) {
    		case 'new-user-first-quote':
    			$user->sendAccountActivationNotification(
		            $this->tokens->create($user), 'activate', $user->email
		        );
    			break;

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x