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] Add types for casting encrypted strings to objects #34948

Merged
merged 1 commit into from
Oct 26, 2020

Conversation

jasonmccreary
Copy link
Contributor

Per the discussion in #34937, this is a fast-follow PR to add "types" or "formats" to specify additional casts for encrypted attributes.

This allows you to persist complex types like arrays, json, objects, or collections as encrypted values, while working with them naturally within your application.

Example:

public $casts = [
    'user_ids' => 'encrypted:array',
    'preferences' => 'encrypted:json',
    'payment_method' => 'encrypted:object',
    'dependents' => 'encrypted:collection',
];

I feel this rounds out this feature by covering the most common use cases. For anything more, a custom cast may be used.

Note: Since these are stored encrypted, you will most like want to use a text field for any attributes using these casts.

@jasonmccreary
Copy link
Contributor Author

@taylorotwell, please make my cascading comment beautiful 😅

@GrahamCampbell GrahamCampbell changed the title Add types for casting encrypted strings to objects [8.x] Add types for casting encrypted strings to objects Oct 24, 2020
@tontonsb
Copy link
Contributor

It has been mentioned before — the real solution would be chainable casts.

But I understand. I've done exactly the same in my own package and even support all of the default Eloquent typecasts on decryption.

@hotmeteor
Copy link
Contributor

@jasonmccreary @tontonsb

I've put together a PR to support chained/chainable casts. Wondering if it might be worth considering this option rather than adding more cast rules?

#34963

@taylorotwell taylorotwell merged commit 1cf5513 into laravel:8.x Oct 26, 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.

4 participants