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

Valuestore Laravel Package

spatie/valuestore

Easily store and retrieve simple key-value data in a JSON file. Valuestore offers a lightweight, framework-friendly API for persisting settings, counters, and small bits of state without needing a database, with atomic writes and optional caching.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: composer require spatie/valuestore
  2. Create a new store instance or use Laravel’s automatic facade binding:
    use Spatie\ValueStore\Facades\Valuestore;
    Valuestore::put('feature_flags', ['dark_mode' => true]);
    
  3. Specify storage location (Laravel defaults to storage/app/valuestore.json—override via config if needed)
  4. First real-world use: store a single app setting or cached transient state without DB overhead, e.g., Valuestore::put('last_deploy_hash', git rev-parse HEAD).

Start by checking the examples/ directory in the repo for minimal usage snippets. In Laravel, you’ll get Valuestore facade out-of-the-box after installation.

Implementation Patterns

  • Config-like persistence: Store runtime-tweakable settings in config/app.php (e.g., Valuestore::put('maintenance_mode', true) instead of editing .env or DB)
  • Feature flags: Use arrays for toggles:
    if (Valuestore::get('features.new_checkout', false)) { ... }
    
  • One-off caches: Persist computed values across requests without cache drivers:
    Valuestore::remember('api_response_cache', 300, fn() => expensiveApiCall());
    
  • CLI tools / scripts: Store ephemeral state between script runs (e.g., migration cursor, progress token)
  • Testing: Use in feature tests to persist test-specific state across assertions:
    Valuestore::put('test_session_id', $id);
    $this->assertEquals($id, Valuestore::get('test_session_id'));
    

For Laravel, extend via Valuestore::extend('custom_key', $callback) to support dynamic default values with fallback logic.

Gotchas and Tips

  • Atomic writes: Avoid concurrent writes under heavy load—use Laravel queues or locks for batch updates.
  • No TTL by default: remember() only works for the current request lifecycle unless manually persisted. For persistent cache with expiration, layer with Laravel’s cache or manually encode timestamps.
  • Performance caveat: Larger files (>1–2MB) or frequent writes may cause slowdowns; avoid using for high-frequency operations (e.g., request counters).
  • Array modifications: Direct array changes (e.g., $data = Valuestore::get('foo'); $data['bar'] = 1;) won’t persist—always re-save: Valuestore::put('foo', $data)
  • Testability: In tests, bind a custom Valuestore instance via Valuestore::fake() or Valuestore::spy() to avoid filesystem side effects
  • Customization: Override default storage path via constructor: new Valuestore(\Storage::path('custom.json'))
  • Debugging tip: Valuestore::all() reveals full contents—use in tinker or debug middleware to inspect stored data.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai