Hi you can use this for hashing
Hash::make($yourPassword)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a custom register page and a login controller and i want to hash the password, how can i go about? thank you
Hi you can use this for hashing
Hash::make($yourPassword)
$password = Hash::make(request('password'));
You can have Laravel automatically hash the password whenever you set the password attribute, like this:
public function setPasswordAttribute($value) {
$this->attributes['password'] = Hash::make($value);
}
Thank you, problem now is that, where can I place this code public function setPasswordAttribute($value) { $this->attributes['password'] = Hash::make($value); } Register controller or model or where, please
That function would go in the model.
@crnkovic cannot still hash bro, I am screwed a bit...can you elaborate more. thank you
Let's start with you showing what you have thus far and what you have tried.
try this
$user->password = Hash::make(request('password'));
$user->save();
@rin4ik , i think your suggestion is i use the php artisan tinker command. But i need to hash a password entered by a user during registration, I have a custom registration form. Thank you
You could also use the helper function bcrypt(...) instead of Hash::make(...) if you're using bcrypt.
So your User.php model would look something like this:
<?php
namespace App;
class User extends Authenticatable
{
...
/**
* Hash the password on save/update.
*/
public function setPasswordAttribute($value) {
$this->attributes['password'] = bcrypt($value);
}
}
In any case, either bcrypt() or Hash::make() within the setPasswordAttribute() method on your User model will result in the password being automatically hashed on save/update.
In my case i added a $cast attribute to the model
protected $casts = [ 'password' = 'hashed' ];
@cocaengasado Yes. That was worth bumping a thread that was half a decade.
Don't roll your own. Use Laravel's Hash::make - https://laravel.com/docs/10.x/hashing
Please or to participate in this conversation.