Skip to content

Instantly share code, notes, and snippets.

@juque
Created September 15, 2023 19:36
Show Gist options
  • Save juque/e27b57e0ac97a0a3f7beff379cf29619 to your computer and use it in GitHub Desktop.
Save juque/e27b57e0ac97a0a3f7beff379cf29619 to your computer and use it in GitHub Desktop.
Laravel: Set new password to user role
<?php
use \App\Models\User;
use Illuminate\Support\Str;
$users = User::where('role', 'user')->get();
foreach($users as $user) {
$newPassword = Str::random(12);
$user->password = bcrypt($newPassword);
$user->save();
printf("%s,%s\n", $user->email, $newPassword);
}
foreach($users as $user) {
printf("%s,%s\n", $user->email, $user->name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment