Support the ongoing development of Laravel.io →
Blade Routing Forms

I did a multi-authentication login between admin and doctors and nurses if it's Admin it redirects it to the admin dashboard and if it's doctors or nurses normally it redirects to password changes if it's the first time log otherwise to a room dashboard except that when I try to change the password the page is displayed in a loop when I click on 'Confirm' without changing the password I tried to debug with dd($request->all()) even that doesn't work I'm new to laravel and I'm lost in it

here is the function in my controller

public function update(Request $request)
    {
        // Valider les données du formulaire
        $request->validate([
            'password' => 'required|string',
            'Newpassword' => 'required|string|confirmed',
        ]);
        //dd($request->all());
        $auth = Auth::user();
 
        // The passwords matches
               if (!Hash::check($request->get('password'), $auth->password)) 
               {
                   return back()->with('error', "Current Password is Invalid");
               }
        
       // Current password and new password same
               if (strcmp($request->get('password'), $request->Newpassword) == 0) 
               {
                   return redirect()->back()->with("error", "New Password cannot be same as your current password.");
               }
        
               $user =  User::find($auth->id);
               $user->password =  Hash::make($request->new_password);
               $user->save();
               return back()->with('success', "Password Changed Successfully");
        
    }

my routes

Route::get('/', [LoginController::class,'login'])->name('Login.login');
Route::post('/', [LoginController::class,'loginPost']);
Route::get('/logout', [LoginController::class,'logout'])->name('logout');

Route::middleware(['auth'])->group(function () {
    Route::get('/administrateur', [AdminController::class,'index'])->name('Admin.index');
    Route::post('/administrateur', [AdminController::class,'store']);
    Route::get('/changer_mot_de_passe', [ChangerMotDePasseController::class,'index'])->name('ChangerMdp.index');
    Route::post('/changer-mot-de-passe', [ChangerMotDePasseController::class, 'update'])->name('postChangerMotDePasse');

    Route::get('/salles', [SallesController::class,'index'])->name('Salles.index');
    // Ajouter les routes pour récupérer les listes des médecins et des infirmiers
    Route::get('/medecins', [AdminController::class,'getMedecins'])->name('Admin.getMedecins');
    Route::get('/infirmiers', [AdminController::class,'getInfirmiers'])->name('Admin.getInfirmiers');
    Route::get('/admin', [AdminController::class,'getAdmins'])->name('Admin.getAdmins');
});

my blade:

<body>

    <div class="logo"><img src="images/logo.png" alt="Logo"></div>
    <div class="container">
        <form id="newpass" action="{{ route('postChangerMotDePasse') }}" method="POST">
        @csrf
        <label for="password">Votre mot de passe actuel:</label>
        <input type="password" class="votre-mot-de-passe-actuel" id="votre-mot-de-passe-actuel" name="password">
        
        <label for="Newpassword">Votre nouveau mot de passe:</label>
        <input type="password" class="votre-nouveau-mot-de-passe" id="Newpassword" name="Newpassword">
        
        <label for="confirmNewPassword">Retappez votre nouveau mot de passe:</label>
        <input type="password" class="retappez-votre-nouveau-mot-de-passe" id="confirmNewPassword" name="confirmNewPassword">
        
        <button type="submit"><span class="confirmer">Confirmer</span></button>
    </form>
    @if (session('error'))
        <p class="error">{{ session('error') }}</p>
    @endif

    @if (session('success'))
        <p class="success">{{ session('success') }}</p>
    @endif
</div>
<script src="js/login.js"></script>
</body>

0

@bmariasirine did you check the roles while changeing password? just redirect user with different roles while updating password.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Maria bmariasirine Joined 8 May 2024

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.