- How do I install npabisz/laravel-settings in a Laravel application?
- Install it with Composer using composer require npabisz/laravel-settings, then publish the package config and migrations and run php artisan migrate. The service provider is typically auto-discovered, but you should confirm the publish tags and supported Laravel versions in the README before adoption. This package is intended for database-backed settings, so plan for a settings table in your application.
- How do I retrieve a setting with laravel-settings?
- The package is designed to let you define settings in code or the database and read them anywhere through helpers or a facade. Retrieval is backed by caching for fast access, so repeated reads should not hit the database every time. Check the README for the exact helper and facade method names in your installed version.
- Which PHP and Laravel versions does npabisz/laravel-settings support?
- The package targets conventional Eloquent-based Laravel applications, but the exact PHP and Laravel version matrix should be verified in its composer.json, README, and CI configuration. The available release note for v1.2.0 does not state a version matrix. Do not assume support for older Laravel releases without confirming it.
- How does caching work in npabisz/laravel-settings?
- The package relies on caching to provide fast access to settings, which is important because database-backed settings would otherwise add a read on the resolution path. Writes should normally invalidate or refresh the relevant cache entries, but you should confirm the exact behavior in the package source or documentation. If you use Laravel's config cache, remember that changing the package configuration is a deploy-time concern.
- Can I use a custom Eloquent model for settings with laravel-settings?
- Yes, v1.2.0 introduced a configurable Setting model class specifically to support DDD and modular application structures. Your custom model must honor whatever contract the package expects and should match the settings table name, connection, primary key, and casts. Test the swap in a non-production environment because a resolved model with missing casts or encryption behavior can fail silently.
- How do I upgrade laravel-settings to v1.2.0 with an existing published config?
- Pin the package to ^1.2 and compare your published config file with the new package config, because the configurable model key may not exist in older published files. Republish the config or manually add the new key, then clear configuration and application caches. Run your settings read and write paths in a staging environment before deploying.
- Is npabisz/laravel-settings suitable for feature flags and admin-editable settings?
- Yes, the package is positioned for feature flags, site options, and admin-editable values that need to change without redeploying. It stores settings persistently and uses caching to keep access fast. For production, consider cache invalidation, backup of the settings table, and access control around any admin UI that writes values.
- How should I test code that uses npabisz/laravel-settings?
- Use Laravel's testing helpers with a test database and run the package migrations, or point the package at a test model and table. Set the cache driver to array during tests so cached settings do not leak between test cases. Include tests for model resolution, casts, encryption, and cache invalidation if you customize the settings model.
- What are the risks of a custom settings model in laravel-settings?
- The main risks are contract durability and silent misconfiguration. If the package requires subclassing rather than implementing an interface, your model inherits vendor internals and may break on minor releases, and a model missing expected casts or encryption can store or read values incorrectly without throwing an exception. Validate class resolution and add integration tests around settings writes and reads.
- What are alternatives to npabisz/laravel-settings?
- Alternatives include spatie/laravel-settings, a custom settings table with your own repository, or Laravel configuration and environment variables for values that do not need admin editing. Compare them on caching behavior, custom model support, Laravel version coverage, test coverage, and maintenance activity before choosing. If DDD model ownership matters, confirm how each package resolves its persistence model.