Files
speedtest-tracker/app/Console/Commands/ResetUserPassword.php
T
Alex Justesen ce21ae24db Laravel 11.x Shift (#1389)
Co-authored-by: Shift <shift@laravelshift.com>
2024-05-06 08:00:29 -04:00

47 lines
1.1 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class ResetUserPassword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:reset-user-password
{email : The email address of the user}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Reset the password for a user\'s account.';
/**
* Execute the console command.
*/
public function handle(): void
{
$user = User::firstWhere('email', $this->argument('email'));
if (! $user) {
// couldn't find the user so should fail.
$this->error('Could not find a user with the email address of '.$$this->argument('email'));
return;
}
$password = $this->secret('What is the password?');
$user->update([
'password' => Hash::make($password),
]);
}
}