#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.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.