Utilise Model Attributes
Accessors, mutators, and attribute casting allow you to transform Eloquent attribute values when you retrieve or set them on model instances.
Eloquent: Mutators & Casting
User Model
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed', // first option
];
}
//second option
protected function password(): Attribute
{
return Attribute::make(
set: fn (string $password) => bcrypt($password),
);
}
}