Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mozew's avatar
Level 6

How to change email to mobile in Laravel 10 to forget the password?

I am new to Laravel and using Laravel 10. I used Laravel UI for auth setup and it's working fine but I want to use mobile auth instead of email auth. How can I do it?

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Notifications\ResetPasswordNotification;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;

class ForgotPasswordController extends Controller
{
    use SendsPasswordResetEmails;
    protected function credentials(Request $request)
    {
        return $request->only('mobile');
    }

    public function sendResetLinkEmail(Request $request)
    {
        $this->validate($request, ['mobile' => 'required|numeric']);
        $user = User::query()->where('mobile', $request->mobile)->first();
        var_dump($user);
        if (!$user) {
           alert('there is not any user');
        }
        $token = Password::broker()->createToken($user);//this function
        $user->notify(new ResetPasswordNotification($token));
        return back()->with('status', trans('passwords.sent'));
    }
}

I get this error

Illuminate\Auth\Passwords\PasswordBroker::createToken(): Argument #1 ($user) must be of type Illuminate\Contracts\Auth\CanResetPassword, null given, called in C:\xampp\htdocs\projects\yazd\vakera\app\Http\Controllers\Auth\ForgotPasswordController.php on line 48

0 likes
1 reply

Please or to participate in this conversation.