Summer Sale! All accounts are 50% off this week.

ignaciodev's avatar

assertDatabaseHas and encrypted casts?

On my model, I cast a column as encrypted:

protected function casts(): array
{
    return [
        'body' => 'encrypted',
    ];
}

But my database assertion fails:

$this->post('/messages', [
    'body' => 'Hello',
]);

$this->assertDatabaseHas('chat_messages', [
    'body' => Crypt::encryptString('Hello'),
    'participant_id' => 1,
]);

How is this usually tested? It works if I remove the encrypted cast.

0 likes
1 reply

Please or to participate in this conversation.