0

I am coded custom user system in Laravel 6.X. In my Login Controller i have this validation code:

    $email = $request->email;
    $validator = Validator::make($request->all(), [
        'email' => 'bail|email|required|max:32|exists:users,email',
        'password' => ['required','min:1','max:32',
        function ($attribute, $value, $fail) {
            $users = DB::table('users')->where('email', $email)->get(); // Get user info (Exception is in here)
            if (hash('sha256', $value) !== $users[0]->Password) { // Check if hashed password equals
                $fail($attribute.' is wrong.'); // If not equal then return error message
            }
        },
    ],
    ]);

I am store my passwords with SHA256 Hashing. If password not equals to database password then return an error message to user. But i am getting an exception "Undefined variable: email".

1 Answer 1

2

Check out this answer: https://stackoverflow.com/a/11086796/7897328. I think you need to use the use keyword.

Your code:

function ($attribute, $value, $fail) {

Your code with the use keyword:

function ($attribute, $value, $fail) use ($email) {
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.