Skip to content

Instantly share code, notes, and snippets.

@luQman704
Created June 19, 2020 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luQman704/a54854506299bbc2576a03f2ee2f7001 to your computer and use it in GitHub Desktop.
Save luQman704/a54854506299bbc2576a03f2ee2f7001 to your computer and use it in GitHub Desktop.
<?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