Installation:
composer require miladimos/conf
Register the service provider in config/app.php:
'providers' => [
// ...
Miladimos\Conf\Providers\ConfServiceProvider::class,
],
Run the installation command:
php artisan conf:install
First Use Case:
Access a config value directly via the conf() helper:
$value = conf('your.key'); // Returns the value from config.json
Ensure config.json is writable:
sudo chown -R $USER config.json
Reading Configs:
conf() helper for quick access:
$apiKey = conf('api.key');
$allConfigs = ConfigJsonService::all();
Storing/Updating Configs:
ConfigJsonService::store([
'key' => 'database.timeout',
'value' => 30,
'description' => 'Database connection timeout in seconds',
]);
ConfigJsonService::update([
'key' => 'database.timeout',
'value' => 60,
], 'database.timeout');
Dynamic Configuration in Controllers:
use Miladimos\Conf\Services\ConfigJsonService;
public function getSettings() {
$settings = ConfigJsonService::show('app.theme');
return response()->json($settings);
}
Environment-Specific Configs:
config.json for staging vs. production).use Illuminate\Support\Facades\Validator;
$validator = Validator::make($request->all(), [
'key' => 'required|string|max:255',
'value' => 'required|string',
]);
$cachedConfig = Cache::remember('config.all', 60, function() {
return ConfigJsonService::all();
});
Route::get('/admin/config', function() {
return ConfigJsonService::all();
})->middleware('admin');
File Permissions:
config.json permissions (chown) will cause Permission denied errors.sudo chown -R $USER config.json after installation.Key Conflicts:
app.name) may break core functionality.custom.app.name).No Built-in Migration:
config.json. Manual edits or custom migrations are needed for version control.API Rate Limiting:
Route::middleware('auth:api')->group(function() {
// Conf routes here
});
Check config.json:
ConfigJsonService::all() to debug missing/incorrect data.Log Errors:
try {
ConfigJsonService::store($data);
} catch (\Exception $e) {
Log::error("Config store failed: " . $e->getMessage());
}
Custom Storage:
config.json by binding a custom storage service:
$this->app->bind('config.storage', function() {
return new CustomConfigStorage();
});
Event Listeners:
Event::listen('conf.stored', function($config) {
Cache::forget('config.all');
});
Validation Rules:
ConfServiceProvider:
$this->app->extend('conf.validator', function() {
return new CustomConfigValidator();
});
API Middleware:
Route::post('/conf/store', [ConfController::class, 'store'])
->middleware('log.config.changes');
How can I help you explore Laravel packages today?