dayploy/doctrine-extensions-bundle
Strengths:
Weaknesses:
BINARY columns) that may conflict with existing migrations or tools (e.g., Laravel Schema).BINARY columns may clash with Laravel’s default string/text columns, necessitating custom migrations.save()/find() could degrade throughput. Benchmarking essential.BINARY columns may complicate future DB migrations or tooling (e.g., Laravel Scout).Strategic Fit:
encrypt() or spatie/laravel-encryption.Architectural Impact:
BINARY columns conflict with existing DB schemas or tools (e.g., Laravel Telescope, Filament)?Operational Readiness:
.env, AWS KMS, HashiCorp Vault) and rotated (manual, automated)?Performance:
Alternatives:
Str::of($value)->encrypt() (simpler, but no field-level granularity).spatie/laravel-encryption (Laravel-specific, but less flexible).pgcrypto, AWS KMS, or Transparent Data Encryption (TDE).Long-Term Viability:
Primary Use Cases:
Recommended Stack:
credit_card_number, ssn).// Custom Repository for encrypted fields
class UserRepository {
public function findById(int $id) {
$db = DBAL::create();
$stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$id]);
$user = $stmt->fetchAssociative();
// Decrypt sensitive fields manually
$user['ssn'] = $this->decrypt($user['ssn_encrypted'], $user['ssn_nonce']);
return $user;
}
}
trait Encryptable {
protected static function bootEncryptable() {
static::saving(function ($model) {
$model->encryptSensitiveFields();
});
static::retrieved(function ($model) {
$model->decryptSensitiveFields();
});
}
protected function encryptSensitiveFields() {
$this->ssn_encrypted = encrypt($this->ssn);
$this->ssn_nonce = generateNonce();
}
protected function decryptSensitiveFields() {
$this->ssn = decrypt($this->ssn_encrypted, $this->ssn_nonce);
}
}
Dependency Conflicts:
gedmo/doctrine-extensions).doctrine/dbal (≥2.13) or doctrine/orm (≥2.10) compatibility.Preparation Phase:
ssn, credit_card_number, api_keys) requiring encryption.BINARY column support in the target database (MySQL/PostgreSQL/SQLite)..env, AWS KMS, HashiCorp Vault) and rotation schedule.Schema Migration:
BINARY columns via Laravel migrations:
Schema::table('users', function (Blueprint $table) {
$table->binary('ssn_nonce')->nullable()->after('ssn');
$table->binary('ssn_encrypted')->nullable()->after('ssn_nonce');
$table->dropColumn('ssn'); // Optional: Remove plaintext column
});
$users = User::all();
foreach ($users as $user) {
$user->ssn_encrypted = encrypt($user->ssn);
$user->ssn_nonce = generateNonce();
$user->ssn = null; // Clear plaintext
$user->save();
}
Integration Phase:
prePersist/preUpdate:
$eventManager = $entityManager->getEventManager();
$eventManager->addEventListener(
'prePersist',
[$this, 'encryptSensitiveFields']
);
Encryptable trait (see above).Testing Phase:
How can I help you explore Laravel packages today?