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

moses's avatar

Laravel password hashes through native php

My code is like this :

echo Hash::make('12345');

error : Fatal error: Class 'Hash' not found in C...

How to call the hash class in laravel through native php

Thank you

0 likes
12 replies
chris97pl's avatar

You probably use namespaced controler action, so you should do this:

echo \Hash::make('12345');

Using Hash without backslash means accessing a class from a current namespace ie. \App\Http\Controller\Hash.

bashy's avatar

Do the above or import the namespace

use Hash;
moses's avatar

I run the code in the php native or php regular, not in laravel. So, whether it can use the hash laravel in regular php?

bashy's avatar

Oh you're not using Laravel? I'm confused.

moses's avatar

@bashy, Yes, I'm not using laravel. I use php native. But, I want to use hash laravel. If it can be done?

moses's avatar

@Juukie, But it's not hash laravel. Although in php native, I wanted to use the hash laravel. If it can be done?

Juukie's avatar

You can require the illuminate/hashing in your composer.json. It'll pull in https://packagist.org/packages/illuminate/hashing.

$hasher = new Illuminate\Hashing\BcryptHasher();
$hash = $hasher->make('foo');

But you could also just manually copy the BcryptHasher.php file if you don't need the Service Provider stuff.

d3xt3r's avatar

Well, simply put you can't. You have to either add dependency as suggested or simply make a call to

$hash = password_hash($valueToHash, PASSWORD_BCRYPT, 10);

Please or to participate in this conversation.