reset password laravel code example

Example 1: disable forgot password in laravel 7

1. Simple Method :  
  Auth::routes(['reset' => false]);

2. If that doesnt work, in ForgotPasswordController, you will see that a trait
    SendsPasswordResetEmails is used, in that you will find the function
    showLinkRequestForm which you can override:

    public function showLinkRequestForm()
    {
        return view('auth.passwords.email');
    }

and replace it with a redirect to go back, or a 404, or something else that you
want.

Example 2: laravel auth reset password

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\User;
use Hash;

class RegisterController extends Controller
{
  public function register()
  {

    return view('auth.register');
  }

  public function storeUser(Request $request)
  {
      $request->validate([
          'name' => 'required|string|max:255',
          'email' => 'required|string|email|max:255|unique:users',
          'password' => 'required|string|min:8|confirmed',
          'password_confirmation' => 'required',
      ]);

      User::create([
          'name' => $request->name,
          'email' => $request->email,
          'password' => Hash::make($request->password),
      ]);

      return redirect('login');
  }

}

Example 3: laravel forgot password example

//You can add validation login here$user = DB::table('users')->where('email', '=', $request->email)    ->first();//Check if the user existsif (count($user) < 1) {    return redirect()->back()->withErrors(['email' => trans('User does not exist')]);}//Create Password Reset TokenDB::table('password_resets')->insert([    'email' => $request->email,    'token' => str_random(60),    'created_at' => Carbon::now()]);//Get the token just created above$tokenData = DB::table('password_resets')    ->where('email', $request->email)->first();if ($this->sendResetEmail($request->email, $tokenData->token)) {    return redirect()->back()->with('status', trans('A reset link has been sent to your email address.'));} else {    return redirect()->back()->withErrors(['error' => trans('A Network Error occurred. Please try again.')]);}

Example 4: custom password reset in laravel

php artisan make:controller Auth/ForgotPasswordController

Tags:

Php Example