Created
June 19, 2020 15:43
-
-
Save luQman704/a54854506299bbc2576a03f2ee2f7001 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\Traits; | |
use Illuminate\Support\Facades\Crypt; | |
trait Encryptable | |
{ | |
public function getAttribute($key) | |
{ | |
$value = parent::getAttribute($key); | |
if (in_array($key, $this->encryptable)) { | |
$value = Crypt::decrypt($value); | |
} | |
} | |
public function setAttribute($key, $value) | |
{ | |
if (in_array($key, $this->encryptable)) { | |
$value = Crypt::encrypt($value); | |
} | |
return parent::setAttribute($key, $value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment