Skip to content

Conversation

djtarazona
Copy link
Contributor

@djtarazona djtarazona commented Nov 17, 2016

This PR is similar to #16443 but the design is a bit different in that you specify attributes to be encrypted in the $encrypts property. This allows attributes to be encrypted and casted.

Use case:

// User.php
class User extends Model
{
    protected $casts = [
        'github_oauth_token' => 'array',
    ];

    protected $encrypts = [
        'github_oauth_token',
    ];
}

// Controller.php (or wherever)
$user = new User();

$user->github_oauth_token = [
    'access_token' => 'abc123...',
    'refresh_token' => 'def456...',
    'expires_at' => 1479423404,
];

$user->getAttributes()['github_oauth_token']; // gibberish (as it is not decrypted) — stored in DB encrypted

This may be considered a breaking change because of the new $encrypts property? If so, I'd be happy to send this to 5.4.

Allows attributes to be encyprted and casted
@djtarazona
Copy link
Contributor Author

Shout out to @alnutile for his great work on #16443, I just need something a bit more flexible that allows me to cast and encrypt attributes. :)

@taylorotwell
Copy link
Member

I would rather have support for multiple casts.

@djtarazona
Copy link
Contributor Author

djtarazona commented Nov 18, 2016

@taylorotwell When supporting multiple casts, you'd have to be careful to make sure that encryption is run after all other casts when setting and decryption before casts when getting.

Also, when would you need multiple casts other than to use encryption with something else? I find it unlikely that you'd, for example, cast to a string and then to an int, etc.

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