Last active
September 17, 2018 20:59
-
-
Save axelitus/d6222e649374aed03f2d06b41150de60 to your computer and use it in GitHub Desktop.
Laravel Database Encryption Use Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// database/migrations/2018_09_17_155927_create_senders_table.php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class CreateSendersTable extends Migration | |
{ | |
public function up() | |
{ | |
Schema::create('senders', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('name'); | |
$table->text('mail_config'); | |
}); | |
} | |
public function down() | |
{ | |
Schema::dropIfExists('senders'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// app/Sender.php | |
namespace App; | |
use AustinHeap\Database\Encryption\Traits\HasEncryptedAttributes; | |
use Illuminate\Database\Eloquent\Model; | |
class Sender extends Model | |
{ | |
use HasEncryptedAttributes; | |
protected $fillable =[ | |
'name', 'mail_config', | |
]; | |
protected $encrypted = [ | |
'mail_config', | |
]; | |
protected $casts = [ | |
'mail_config' => 'array', | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// database/factories/SenderFactory.php | |
use Faker\Generator as Faker; | |
$factory->define(App\Sender::class, function (Faker $faker) { | |
return [ | |
// | |
]; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// database/seeds/SendersTableSeeder.php | |
use App\Sender; | |
use Illuminate\Database\Seeder; | |
class SendersTableSeeder extends Seeder | |
{ | |
public function run() | |
{ | |
factory(Sender::class)->create([ | |
'name' => 'Log Sender', | |
'mail_config' => [ | |
'driver' => 'log', | |
'host' => null, | |
'port' => null, | |
'username' => null, | |
'password' => null, | |
'encryption' => null, | |
'from' => [ | |
'address' => 'admin@localhost', | |
'name' => 'Local Admin', | |
] | |
], | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment