1. Go to this page and download the library: Download diontech/laravel-vault library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
diontech / laravel-vault example snippets
//creating a vault without a related model
$vault = \DionTech\Vault\Models\Vault::create([
'name' => 'application vault'
]);
//use default APP_KEY, adding secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->add("facaded_secret", "AN_API_KEY");
//use default APP_KEY, overwrite secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->overwrite("facaded_secret", "AN_API_KEY_overwritten");
//use default APP_KEY, get secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->get("facaded_secret");
//use own key, adding secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->add("facaded_secret", "AN_API_KEY");
//use own key, overwrite secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->overwrite("facaded_secret", "AN_API_KEY_overwritten");
//use own key, get secret
\DionTech\Vault\Support\Facades\Vault::open($vault)->useKey("DO_NOT_FORGETT_IT")->get("facaded_secret");
//adding a vault using the polymorphic relation
//at your model, add morphMany relation, for example at User:
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
//...
public function vaults()
{
return $this->morphMany(\DionTech\Vault\Models\Vault::class, 'vaultable');
}
}
//now add a vault at an $user instance later
$user = User::first();
$user->vaults()->create([
'name' => 'personal'
]);
//now you will have access to the methods like using a facade when you will use the related model based vaults(), starting with open()
$user->vaults()->first()->add("AN_API_KEY", "this-is-the-sensible-value");
$user->vaults()->first()->overwrite("AN_API_KEY", "this-is-the-sensible-value-overwritten");
$user->vaults()->first()->get("AN_API_KEY");
Vault::open("a vault name")->add("facaded_secret", "simple value"); //will create the vault
$user = User::first();
Vault::setContext($user)->open("personal")->add('bad_password_storing_itself', '12345678'); //will create a vault in relation to the user
shell
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.