ldc-legaulois/app/Console/Commands/UserChangePassword.php
2022-02-10 16:14:58 +01:00

43 lines
923 B
PHP

<?php
namespace App\Console\Commands;
use App\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Hash;
class UserChangePassword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user:password';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Changes a user password';
public function handle()
{
$email = $this->ask('What is the email?');
$user = User::where('email', $email)->first();
if (!$user) {
$this->error(sprintf('User %s could not be found', $email));
return -1;
}
$password = $this->secret('What is the password?');
$user->password = Hash::make($password);
$user->saveOrFail();
$this->info('User updated.');
return 0;
}
}