Skip to content

Conversation

@alnutile
Copy link
Contributor

This would allow the user to easily encrypt and decrypt a field by setting it to that cast

For example

    protected $casts = [
        'secret' => 'encrypt',
        'data' => 'array'
    ];

This would allow the user to easily encrypt and decrypt a field by setting it to that `cast`

For example

```
    protected $casts = [
        'secret' => 'encrypt',
        'data' => 'array'
    ];
```
@taylorotwell taylorotwell merged commit 278f136 into laravel:5.3 Nov 17, 2016
@alnutile alnutile deleted the patch-1 branch November 17, 2016 14:35
@alnutile
Copy link
Contributor Author

Should I go update the docs? @taylorotwell

@lukepolo
Copy link
Contributor

Awesome , I had written this as a trait numerous times ~

@GrahamCampbell GrahamCampbell changed the title Offer an "Attribute Casting" of encrypt [5.3] Offer an "Attribute Casting" of encrypt Nov 17, 2016
@alnutile
Copy link
Contributor Author

alnutile commented Nov 17, 2016

:)

@djtarazona
Copy link
Contributor

djtarazona commented Nov 17, 2016

Should this be a "cast"? I've written something similar into my models but using a separate $encrypts property. With this implementation, to my understanding, you wouldn't be able to decrypt an attribute and then cast it to an interger? Or a decrypt and cast to an array?

My use case is storing OAuth tokens. I store the access token, refresh token, and expiration in an array and assign it to an attribute with the array cast. I then also mark that attribute as "encrypts" so that when settting, the array is serialized and then encrypted. When accessing the attribute, the value is decrypted and then deserialized to an array.

Edit: To address my use case, I've created #16457 to change this functionality.

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