PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, February 20, 2022

[FIXED] laravel reset password custom validator?

 February 20, 2022     laravel, laravel-5, laravel-5.4, php     No comments   

Issue

by looking at ResetsPasswords code I can see that rules method is protected:

 protected function rules()
    {
        return [
            'token' => 'required',
            'email' => 'required|email',
            'password' => 'required|confirmed|min:6',
        ];
    }

what is the appropriate way in laravel of adding another custom validation into the reset password form if I cant override the rules method?

I can override the reset method but its too big and if in the future versions they will change some logic I will be in trouble as I don't want to mess too much with security features


Solution

Laravel has some basic auth controllers in App\Http\Controllers\Auth;

One of them is the ResetPasswordController controller, that is loading the trait.

In this class you can just overwrite the rules() function.

If you don't want to update the rules() function, you have to update the reset() function to modify your array. But I do not suggest this, because this function is more complex and will be changed obviously than the rules() function.

If you want to update the trait, you can extend it like this:

trait CustomResetsPasswords {
    use ResetsPasswords;

    public function rules() {
        //return my custom rules
    }
}

An then in the ResetPasswordController you use your CustomResetsPasswords trait.



Answered By - cre8
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing