Im new to Laravel / Lumen framework and im trying to replicate the the default reset password trait for Laravel https://laravel.com/docs/5.7/passwords to my Lumen Project. However, I stumbled upon this error when I post to sumbit email endpoints.
Error Encountered {"message":"Target class [auth.password] does not exist."}
My Route
$router->post('password/email', 'AuthController@postEmail');
Methods
public function postEmail(Request $request)
{
return $this->sendResetLinkEmail($request);
}
/**
* Send a reset link to the given user.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function sendResetLinkEmail(Request $request)
{
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
// dd($request->all());
$response = $this->broker()->sendResetLink(
$request->only('email')
);
return $response == Password::RESET_LINK_SENT
? response()->json(true)
: response()->json(false);
}
and it uses this class use Illuminate\Support\Facades\Password;
and I think the error is fired by this method
protected static function getFacadeAccessor()
{
return 'auth.password';
}
}
I saw that this getFacadeAccesor return string is registered in namespace Illuminate\Foundation;
but I can't find this file in my Lumen vendor folder. Any workaround on this? Thank you!
You could try registering the Illuminate\Auth\Passwords\PasswordResetServiceProvider
Service Provider in bootstrap/app.php
:
...
// $app->register(App\Providers\EventServiceProvider::class);
$app->register(Illuminate\Auth\Passwords\PasswordResetServiceProvider::class);
This Service Provider is what adds the binding for auth.password
:
protected function registerPasswordBroker()
{
$this->app->singleton('auth.password', function ($app) {
return new PasswordBrokerManager($app);
});
$this->app->bind('auth.password.broker', function ($app) {
return $app->make('auth.password')->broker();
});
}
That just resolves the auth.password
binding, you still have other issues to deal with.
Your User will need to be using the Illuminate\Auth\Passwords\CanResetPassword
trait but also the Illuminate\Notifications\Notifiable
trait which you won't have as that Illuminate package isn't installed.
You would have to not use the sendResetLink
of the Password Broker, which uses the notify
method (from Notifiable
) on the User, and build this part of the functionality yourself at the least.
Unfortunately if you start needing pieces of the Laravel Framework (Illuminate packages) that don't come with Lumen, you are going in the direction of using the Laravel Framework instead of Lumen, often times.