-
app/Rules/CurrentPasswordRule.php
Open in GitHubclass CurrentPasswordRule implements Rule { public function passes($attribute, $value) { if (!Hash::check($value, Auth::User()->password)) { return false; } return true; } public function message() { return 'Users details don\'t match our records.'; } }
-
app/Http/Requests/ChangePasswordRequest.php
Open in GitHubclass ChangePasswordRequest extends FormRequest { // ... public function rules() { return [ 'current' => ['required', new CurrentPasswordRule ], 'password' => ['required', 'confirmed'] ]; } }
-
app/Http/Controllers/ProfileController.php
Open in GitHub// ... other use statements use App\Http\Requests\ChangePasswordRequest; class ProfileController extends Controller { // ... other methods public function password(ChangePasswordRequest $request): RedirectResponse { $user = Auth::User(); $user->update([ 'password' => Hash::make($request['password']) ]); return redirect(route('profile.settings.account'))->with('passwordStatus', 'Password Changed Successfully'); } }