Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Valuestore

Laravel Valuestore Laravel Package

spatie/laravel-valuestore

Store and retrieve loose key/value data in a JSON file with a simple API. Supports put/get with defaults, has/all, forget/flush, increment, and helpers like ArrayAccess and Countable—handy for app settings or small persistent state.

View on GitHub
Deep Wiki
Context7

Easily store some values

Frequently asked questions about Laravel Valuestore
How do I install spatie/laravel-valuestore in my Laravel project?
Run `composer require spatie/laravel-valuestore` in your project directory. No additional configuration is needed—it integrates seamlessly with Laravel’s filesystem. The default JSON file is stored at `storage/app/valuestore.json`.
What Laravel versions does this package support?
spatie/laravel-valuestore supports Laravel 8.x, 9.x, and 10.x. Check the [GitHub repository](https://github.com/spatie/valuestore) for the latest compatibility details before upgrading.
Can I use this for production feature flags or app configurations?
Yes, but ensure file permissions restrict access to the JSON file (e.g., `storage/app` should be writable only by the web server user). For sensitive data, encrypt values using Laravel’s built-in encryption (e.g., `config/encryption.php`).
How do I handle concurrent writes to the JSON file in a multi-server environment?
Use Laravel’s `Storage::lock()` to prevent race conditions. For distributed setups, consider a shared database or caching layer (e.g., Redis) instead, as JSON file storage isn’t designed for concurrent writes across servers.
What’s the difference between `put()` and `put(['key1' => 'value1'])`?
Both methods store key-value pairs, but the array syntax (`put(['key1' => 'value1'])`) lets you write multiple keys in a single operation. This is useful for bulk updates, like initializing a store with default settings.
How do I cache the JSON file for better performance?
Wrap `Valuestore::all()` or `Valuestore::get()` calls in Laravel’s cache (e.g., `Cache::remember('valuestore', 60, fn() => Valuestore::all())`). This reduces file I/O but requires manual cache invalidation when data changes.
Is there a way to use a database instead of a JSON file?
No, this package is designed for JSON file storage only. For database-backed settings, use alternatives like `spatie/laravel-settings`, which supports MySQL, PostgreSQL, and SQLite.
How do I test Valuestore in PHPUnit?
Mock the `Valuestore` interface or use Laravel’s `Storage` facade to simulate file operations. Test edge cases like concurrent writes by temporarily disabling file locking in tests.
What happens if the JSON file gets corrupted?
The package will throw an exception if the file is unreadable. To mitigate corruption, ensure atomic writes (e.g., write to a temp file and rename it) and validate JSON structure on read.
Can I use Valuestore for user-specific settings instead of sessions?
Yes, but avoid storing large or sensitive data. For scalability, consider Laravel’s built-in session driver or a dedicated database table. Valuestore is best for small, app-wide configurations.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport