composer require bella-baxter/symfony in your Laravel project.config/app.php under providers:
BellaBaxter\Symfony\BellaBundle::class,
php artisan vendor:publish --provider="BellaBaxter\Symfony\BellaBundle" and update .env:
BELLA_BAXTER_URL=https://api.bella-baxter.io
BELLA_BAXTER_API_KEY=bax-your-api-key
$_ENV or getenv() in a controller or service:
$dbUrl = $_ENV['DATABASE_URL'];
Environment-Based Secrets:
auto_load: true (default) to inject secrets into $_ENV on the first HTTP request.$_ENV, getenv(), or $_SERVER in any part of your application (controllers, services, commands).Service Injection:
BaxterClient directly into services for programmatic access to secrets:
use BellaBaxter\BaxterClient;
class DatabaseService {
public function __construct(private BaxterClient $bella) {}
public function getConnection() {
$url = $this->bella->getSecret('DATABASE_URL');
// Use $url
}
}
Lazy Loading:
auto_load in config/packages/bella.yaml and manually trigger secret loading:
$this->bella->loadSecrets();
Environment-Specific Secrets:
production, staging) to load context-specific secrets:
bella:
environment: '%env(APP_ENV)%'
APP_ENV matches Bella Baxter’s environment tags for correct secret loading.loadSecrets().env() helper with defaults for critical secrets:
$dbUrl = env('DATABASE_URL', $_ENV['DATABASE_URL'] ?? 'fallback-url');
Timing Issues:
$_ENV in service constructors or boot methods before the request lifecycle starts.BaxterClient injection or defer secret access until a controller/action.Configuration Overrides:
config/packages/bella.yaml overrides .env values. Ensure consistency:
bella:
url: 'https://custom-bella-url.io' # Overrides BELLA_BAXTER_URL
API Key Exposure:
.env or config/packages/bella.yaml to version control. Use Laravel’s .env.example for placeholders.Circular Dependencies:
BaxterClient into providers or boot methods that run before the bundle initializes.if (!isset($_ENV['DATABASE_URL'])) {
throw new \RuntimeException('Secrets not loaded!');
}
config/packages/bella.yaml:
bella:
debug: true
Check Laravel logs for loading errors.Custom Secret Handlers:
BaxterClient to transform secrets before injection:
$this->bella->on('secret.loaded', function ($secret) {
$_ENV[strtoupper($secret['name'])] = base64_decode($secret['value']);
});
Event Listeners:
bella.secrets.loaded events to react to secret changes:
use BellaBaxter\Events\SecretsLoaded;
public function handle(SecretsLoaded $event) {
// Refresh cache or update services
}
Fallback Secrets:
env() helper for hybrid secret management:
$secret = env('SECRET_KEY', $_ENV['SECRET_KEY'] ?? 'default');
auto_load Behavior:
false to manually control loading (e.g., in a command):
$this->bella->loadSecrets(); // Explicit trigger
BELLA_BAXTER_ to avoid conflicts with Laravel’s defaults.How can I help you explore Laravel packages today?