Regenerate Boost guidelines and skills
Generated by boost:update for Boost 2.8, which replaces the pest-testing skill with testing-best-practices and adds infer-conventions. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017XYnWFt9pJEwvAmNFN38XD
This commit is contained in:
co-authored by
Claude Opus 5
parent
3638455167
commit
92b3b3de56
@@ -1,73 +1,85 @@
|
||||
# Configuration Best Practices
|
||||
|
||||
## `env()` Only in Config Files
|
||||
## Read Environment Variables in Configuration Files
|
||||
|
||||
Direct `env()` calls may return `null` when config is cached.
|
||||
Call `env()` only from configuration files. After configuration is cached, Laravel does not load the application's `.env` file, so application code should read configuration values through `config()`.
|
||||
|
||||
Incorrect:
|
||||
|
||||
```php
|
||||
$key = env('API_KEY');
|
||||
```
|
||||
|
||||
Correct:
|
||||
|
||||
```php
|
||||
// config/services.php
|
||||
'key' => env('API_KEY'),
|
||||
return [
|
||||
'key' => env('API_KEY'),
|
||||
];
|
||||
|
||||
// Application code
|
||||
$key = config('services.key');
|
||||
```
|
||||
|
||||
## Use Encrypted Env or External Secrets
|
||||
## Protect Production Secrets
|
||||
|
||||
Never store production secrets in plain `.env` files in version control.
|
||||
Do not commit plaintext production secrets. Laravel can encrypt an environment file so its encrypted form can be stored safely, while deployment platforms can supply secrets through their native secret stores.
|
||||
|
||||
Incorrect:
|
||||
|
||||
```bash
|
||||
|
||||
# .env committed to repo or shared in Slack
|
||||
|
||||
# A plaintext .env file committed to the repository
|
||||
STRIPE_SECRET=sk_live_abc123
|
||||
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI
|
||||
```
|
||||
|
||||
Correct:
|
||||
Encrypted environment file:
|
||||
|
||||
```bash
|
||||
php artisan env:encrypt --env=production --readable
|
||||
php artisan env:decrypt --env=production
|
||||
```
|
||||
|
||||
For cloud deployments, prefer the platform's native secret store (AWS Secrets Manager, Vault, etc.) and inject at runtime.
|
||||
For hosted deployments, consider the platform's native secret store, such as AWS Secrets Manager or Vault, and inject secrets at runtime.
|
||||
|
||||
## Use `App::environment()` for Environment Checks
|
||||
|
||||
Incorrect:
|
||||
|
||||
```php
|
||||
if (env('APP_ENV') === 'production') {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
Correct:
|
||||
|
||||
```php
|
||||
if (app()->isProduction()) {
|
||||
// or
|
||||
// ...
|
||||
}
|
||||
|
||||
if (App::environment('production')) {
|
||||
// ...
|
||||
}
|
||||
```
|
||||
|
||||
## Use Constants and Language Files
|
||||
## Name Repeated Domain Values
|
||||
|
||||
Use class constants instead of hardcoded magic strings for model states, types, and statuses.
|
||||
Use an enum or class constant when a domain value is repeated or represents a constrained set. A one-off string literal does not always need a named constant.
|
||||
|
||||
```php
|
||||
// Incorrect
|
||||
// Repeated literal
|
||||
return $this->type === 'normal';
|
||||
|
||||
// Correct
|
||||
// Named domain value
|
||||
return $this->type === self::TYPE_NORMAL;
|
||||
```
|
||||
|
||||
If the application already uses language files for localization, use `__()` for user-facing strings too. Do not introduce language files purely for English-only apps — simple string literals are fine there.
|
||||
If the application supports localization, put user-facing strings in language files and retrieve them with `__()`. Simple literals are reasonable for applications that intentionally do not support multiple languages.
|
||||
|
||||
```php
|
||||
// Only when lang files already exist in the project
|
||||
// In a localized application
|
||||
return back()->with('message', __('app.article_added'));
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user