Have you tried with a simple string ?
class Profile extends Model
{
protected $casts = [
'test' => 'encrypted',
];
}
Just to check if it works for a simple string.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey,
The docs at https://laravel.com/docs/12.x/eloquent-mutators#encrypted-casting mention encrypted:object to cast a col autoencrypted to an object. That sounds great, but I can not find examples of how to do it.
Do I still need my own custom Casting-Class or should the ValueObject be enought?
I tried it like this
class Profile extends Model
{
protected $casts = [
'verified_information' => 'encrypted:object,App\ValueObjects\VerifiedInformation',
];
}
class VerifiedInformation
{
public function __construct(
public string $prename,
public string $surname,
public int $salary
) {}
public function __toString()
{
return json_encode([
'prename' => $this->prename,
'surname' => $this->surname,
'salary' => $this->salary
]);
}
}
But that has multiple issues:
I hoped that the ':object'-part would somehow do lifting for the dev.
Why not just encrypted:object instead of encrypted:object,App\ValueObjects\VerifiedInformation ?
I don't see anything in the documentation saying that it's necessary to specify the object model.
Please or to participate in this conversation.