crudly/encrypted package provides Eloquent model encryption via Laravel's attribute casting, making it ideal for:
use declaration and model attribute configuration (e.g., protected $casts = ['ssn' => Encrypted::class])..env or a secrets manager).WHERE, JOIN, or ORDER BY clauses without additional logic (e.g., application-side filtering).openssl).composer require crudly/encrypted..env (e.g., ENCRYPTION_KEY=base64:...).Encrypted cast (e.g., protected $casts = ['credit_card' => Encrypted::class]).$users = User::all();
foreach ($users as $user) {
$user->forceFill(['credit_card' => $user->credit_card])->save();
}
spatie/laravel-encryption).Encrypted.null in Tinker/Artisan if decryption fails. Log decryption errors to track key issues.encrypted: prefix in API responses (if needed).Cache::remember) for read-heavy workloads.public function getCreditCardAttribute($value) {
return Cache::remember("user_{$this->id}_credit_card", now()->addHours(1), function() {
return decrypt($value);
});
}
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Lost encryption key | Permanent data loss | Backup keys in a secure vault (e.g., AWS KMS). |
| Corrupted encrypted data | Field appears as null |
Regular data integrity checks. |
| Key rotation without re-encryption | Data becomes unreadable | Automate re-encryption during rotation. |
PHP openssl extension missing |
Decryption fails | Ensure openssl is enabled in PHP-FPM. |
| High query load on encrypted fields | Increased latency | Cache decrypted values or offload to queues. |
null...").How can I help you explore Laravel packages today?