Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Model::encryptUsing() #35080

Merged
merged 2 commits into from
Nov 3, 2020

Conversation

hivokas
Copy link
Contributor

@hivokas hivokas commented Nov 3, 2020

encrypted casts have been added to Laravel recently. While this feature is extremely useful, sometimes developers may want to use the separate key to encrypt database values. Currently, that's not possible. However, this PR introduces this ability by adding Model::encryptUsing() method that accepts encrypter instance that will be used to perform encryption-related casts.

The most typical use of this would be a similar piece of code in AppServiceProvider or in a separate service provider:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Encryption\Encrypter;

$databaseEncryptionKey = config('database.encryption_key');

$encrypter = new Encrypter($databaseEncryptionKey);

Model::encryptUsing($encrypter);

@taylorotwell taylorotwell merged commit 71dbf22 into laravel:8.x Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants