Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

webmaster-lawnstarter's avatar

L5: PHP Fatal error: Class 'Hash' not found

I have a few helper methods for my PHPUnit tests. Once of them creates a new user account with a standard password. Before the most recent updates I set the password using the following line:

$user->password = Hash::make('---some---password---here---');

I ran a composer update this morning and since then I get a

PHP Fatal error:  Class 'Hash' not found in /home/vagrant...

even the following does not work

$user->password = \Hash::make('---some---password---here---');

How can I do this with the latests updates to the framework?

0 likes
2 replies
bashy's avatar

Use the full namespace at the top?

I know in 4.2.* it's this

use Illuminate\Support\Facades\Hash;
MThomas's avatar

Ore inject the Hasher contract:

use Illuminate\Contracts\Hashing\Hasher

class MyClass {

    public function __construct(Hasher $hasher)
    {
        $this->hasher = $hasher;
    }

    public function MyAwsomeMethod()
    {
        $user->password = $this->hasher->make('---some---password---here---');
    }

}

Please or to participate in this conversation.