'Class 'App\Http\Controllers\Hash' not found

I'm trying to use Hash in my global functions file.

I keep getting this error.

Class 'App\Http\Controllers\Hash' not found

where my file below is located at:

/app/Helpers/functions.php

<?php

    use App\Http\Controllers\Hash;

    // If old password matches password
    function checkOldPassword($oldPassword, $user) {
        if (Hash::check($oldPassword, $user->password)) {
            dd('a');
        }
        else {
            return back()->withErrors([
                'message' => 'Your old password is incorrect.'
            ]);
        }
    }


Solution 1:[1]

import the hash class from use Illuminate\Support\Facades\Hash;

Solution 2:[2]

Hash is a facade. It is working in your controller because has been imported correctly: use Hash; However, in other classes or files, you need to import it as mentioned or using it without making an inclusion but backslash:

<?php

// If old password matches password
function checkOldPassword($oldPassword, $user) {
    if (\Hash::check($oldPassword, $user->password)) {
        dd('a');
    }
    else {
        return back()->withErrors([
            'message' => 'Your old password is incorrect.'
        ]);
    }
}

Solution 3:[3]

As the error helpfully points out, there is no class App\Http\Controllers\Hash unless you created one. Remove that line your code should behave normally.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sajjad Aljileezi
Solution 2 manix
Solution 3 Andrew Gillis