vendredi 15 février 2019

My Encrypt function doesn't run at Laravel.5

I would like to encrypt Laravel data. I wrote below code and run but it doesn't work. Could someone teach me what is wrong my code please?

App/Encryptable.php

namespace App;
use Crypt;

trait Encryptable
{
    public function getAttribute($key)
    {
        $value = parent::getAttribute($key);
        if (in_array($key, $this->encryptable)) {
            $value = Crypt::decrypt($value);
            return $value;
        }
        return $value;
    }

    public function setAttribute($key, $value)
    {
        if (in_array($key, $this->encryptable)) {
            $value = Crypt::encrypt($value);
        }
        return parent::setAttribute($key, $value);
    }
}

This is my Controller code. I adjust these code and run many time but everytime another error come up.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Encryptable;

class Article extends Model

{
    use Encryptable; 

    protected $fillable = [

        'title', 'body'

    ];


    public $encryptable = [
        'title', 'body'
    ];


}



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2GLHFUh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire