@mozew Check this beautiful explianed Blog Post By Twilio for auth change to mobile instead email https://www.twilio.com/en-us/blog/implement-account-verification-login-by-phone-laravel-php
Feb 29, 2024
1
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
Please or to participate in this conversation.