#database #development #laravel #php

If you want to put "sensitive" data in our database then you can use Crypt Facade and handle these using accessors and mutators.

 1namespace App\Models;
 2
 3use Illuminate\Database\Eloquent\Model;
 4use Illuminate\Database\Eloquent\Casts\Attribute;
 5use Illuminate\Support\Facades\Crypt;
 6
 7class CloudProvider extends Model
 8{
 9    protected function apiToken(): Attribute
10    {
11        return Attribute::make(
12            set: fn ($value) => Crypt::encryptString($value),
13            get: fn ($value) => Crypt::decryptString($value),
14        );
15    }
16}

Thanks to @thkafadaris for the idea.