1. Go to this page and download the library: Download gause/laravel-keyring 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/ */
gause / laravel-keyring example snippets
use Keyring\Facades\Keyring;
// Via facade
$secret = Keyring::get('STRIPE_SECRET');
// Via helper
$secret = keyring('STRIPE_SECRET');
$secret = keyring('STRIPE_SECRET', 'fallback-value');
// Via dependency injection
public function __construct(KeyringManager $keyring)
{
$secret = $keyring->get('STRIPE_SECRET');
}
use Keyring\Facades\Keyring;
use Keyring\Contracts\Driver;
// In a service provider boot() method
Keyring::extend('vault', function ($app) {
return new HashiCorpVaultDriver(
url: config('keyring.drivers.vault.url'),
token: config('keyring.drivers.vault.token'),
);
});
use Keyring\Contracts\Driver;
class HashiCorpVaultDriver implements Driver
{
public function get(string $key): ?string { /* ... */ }
public function set(string $key, string $value): void { /* ... */ }
public function forget(string $key): void { /* ... */ }
public function has(string $key): bool { /* ... */ }
public function all(): array { /* ... */ }
}
Keyring::driver('vault')->get('DATABASE_URL');
return [
// Driver: auto, keychain, secret-service, wincred, env, json
'default' => env('KEYRING_DRIVER', 'auto'),
// Namespace prefix for secrets
'namespace' => env('KEYRING_NAMESPACE', env('APP_NAME', 'Laravel')),
// Throw exception on missing keys
'strict' => env('KEYRING_STRICT', false),
// Inject secrets into $_ENV at boot
'inject_into_env' => env('KEYRING_INJECT', true),
// Specific keys to inject (empty = all)
'inject_keys' => [],
// Cache resolved secrets in RAM (opt-in,
bash
# Stop the root-owned PHP service
sudo brew services stop php
# Start PHP under your user (no sudo!)
brew services start php
# Restart Valet
valet restart