betterapp/laravel-db-encrypter
Crypt facade, reducing dependency sprawl and aligning with existing security patterns.$encryptable array), enabling selective protection without full-table encryption.WHERE clauses, limiting searchability.config['encryptable']).$encryptable to models; encrypt on first write.TEXT columns may double storage (e.g., 255 → 512 chars for AES-256).APP_KEY; rotation requires re-encryption of all data.SQLSTATE[HY000]: General error for malformed ciphertext).$encryptable post-deployment requires data migration.APP_KEY is lost? (Backup plan required.)#[Encryptable] in future versions?).TEXT column advice is MySQL-specific.password, credit_card).api_tokens) first.TEXT; backfill encrypted data.$encryptable to models; update API responses to auto-decrypt.Model::find() returns decrypted data).null, max TEXT length.| Phase | Tasks |
|---|---|
| Pre-Req | Upgrade to PHP 8.2+; Laravel 11/12. Backup database. |
| Dev Environment | Install package; test in staging with a subset of models. |
| Data Migration | Script to re-encrypt existing data (use DB::transaction). |
| Code Changes | Update models, controllers, and API responses. |
| QA | Test edge cases (e.g., concurrent writes, large payloads). |
| Monitoring | Log decryption failures; alert on performance degradation. |
spatie/laravel-encryption).APP_KEY loss.DecryptException (corrupted data, wrong key).SQLSTATE[22001] (string truncation in VARCHAR columns).dd($model->getOriginal()).static properties).TEXT columns may fragment indexes; monitor query performance.| Scenario | Impact | Mitigation |
|---|---|---|
APP_KEY loss |
Permanent data lockout | Offline decryption script; backup keys. |
| Corrupted ciphertext | Silent data loss | Validate decryption in accessors. |
| PHP/Crypt extension failure | App crashes | Fallback to plaintext (with warnings). |
| Storage full (TEXT bloat) | DB writes fail | Monitor disk usage; optimize fields. |
| Multi-process race conditions | Inconsistent decryption | Use synchronized locks for writes. |
How can I help you explore Laravel packages today?