<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\User;
class ResetPassword extends Command
{
protected $signature = 'reset:password';
protected $description = 'reset password for a user';
public function __construct()
{
parent::__construct();
}
public function handle()
{
$id = $this->ask('请输入你想重置密码的用户ID');
$user = User::find($id);
if(!$user){
return $this->error('用户不存在');
}
$password = $this->secret('请输入用户密码');
if(strlen(trim($password)) < 6){
return $this->error('密码长度不能少于6位');
}
$user->password = bcrypt($password);
$user->save();
$this->info('密码重置成功');
}
}