Please use the below passwordResetToken() function to get the token for password reset for custom use.
namespace App\Traits;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Password;
trait ResetPasswordTrait
{
...
...
...
...
/**
* Get the token for password reset and update the token in the database table.
*
* @return string|null
*/
public function passwordResetToken($user)
{
$this->broker = 'users';
$broker = $this->getBroker();
return Password::broker($broker)->createToken($user);
}
/**
* Get the broker to be used during password reset.
*
* @return string|null
*/
public function getBroker()
{
return property_exists($this, 'broker') ? $this->broker : null;
}
}
// Reuse in the class
use App\Traits\ResetPasswordTrait;
class NewUserAccount
{
use ResetPasswordTrait;
// Sample function to print the password reset token
public function printPasswordResetToken(Request $request)
{
$user = User::find( $request->input('id') );
$passwordResetToken = $this->passwordResetToken($user);
print_r($passwordResetToken);
}
}
