app/Traits/Encryptable.php
use Illuminate\Support\Facades\Crypt; trait Encryptable{ public function getAttribute($key) { $value = parent::getAttribute($key); if (\in_array($key, $this->encryptable, true)) { return Crypt::decrypt($value); } return $value; } public function setAttribute($key, $value) { if (\in_array($key, $this->encryptable, true)) { $value = Crypt::encrypt($value); } return parent::setAttribute($key, $value); }}