Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Encrypt Model

Laravel Encrypt Model Laravel Package

jetiradoro/laravel-encrypt-model

Laravel trait to transparently encrypt specified Eloquent model attributes before saving to the database and automatically decrypt them when accessed. Install via Composer, add the Encryptable trait, and list encrypted fields in the $encryptable array.

View on GitHub
Deep Wiki
Context7

Encrypt data before insert database

Frequently asked questions about Laravel Encrypt Model
How do I encrypt specific fields in a Laravel Eloquent model using this package?
Add the `Encryptable` trait to your model and define a `$encryptable` array listing the fields to encrypt. For example, `protected $encryptable = ['cc', 'ss', 'phone'];`. The package handles encryption on save and decryption on retrieval automatically.
Does this package work with Laravel 10 or newer versions?
Yes, the package is compatible with Laravel 8+ and newer versions. It leverages Eloquent’s standard behavior, so it integrates seamlessly with the latest Laravel releases without breaking changes.
Can I use custom encryption algorithms (e.g., AES-256-GCM) instead of Laravel’s default?
No, this package relies on Laravel’s built-in encryption (via `encrypt()`/`decrypt()` helpers). For custom algorithms, you’d need to extend the package or use a dedicated library like Defuse/PHP-Encryption.
Will encrypted fields break Laravel’s query builder (e.g., `where('cc', 'LIKE', '%123%')`)?
Yes, encrypted fields cannot be queried directly. If you need searchable encrypted data, consider using a dedicated search solution (e.g., Elasticsearch) or database-level encryption (e.g., PostgreSQL’s `pgcrypto`).
How does this package handle key rotation if I change Laravel’s APP_KEY?
The package uses Laravel’s default encryption key (`APP_KEY`). If you rotate the key, previously encrypted data will become unreadable. Always back up encrypted data before rotating keys, and consider field-level keys for compliance.
Is there a performance impact when encrypting/decrypting fields on every save/load?
Yes, encryption adds overhead. For high-write workloads, benchmark the package’s impact on your application. If performance is critical, consider database-level encryption or caching decrypted values.
Can I encrypt only certain records (e.g., per-user keys) instead of all fields globally?
No, this package uses a single encryption key (`APP_KEY`) for all encrypted fields. For per-record encryption, you’d need a custom solution or a package like `spatie/laravel-encryption`.
Does this package support encrypted field indexing or partial searches?
No, encrypted fields are stored as encrypted blobs and cannot be indexed or searched directly. For advanced search, use a dedicated encrypted search solution like OpenFHE or Elasticsearch with encrypted fields.
How do I test models with encrypted fields in PHPUnit?
Mock Laravel’s encryption helpers (`encrypt`, `decrypt`) in your tests to avoid relying on `APP_KEY`. Use `Hash::fake()` or `Str::random()` for predictable test data, then verify decryption works as expected.
What are the alternatives to this package for Laravel model encryption?
Alternatives include `spatie/laravel-encryption` (for field-level keys), `defuse/php-encryption` (custom algorithms), or database-level solutions like PostgreSQL’s `pgcrypto`. Choose based on your need for key management, compliance, or searchability.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle