Value Store
TheValueStore model provides a database-backed key-value storage system for application settings and configuration data. This replaces filesystem-based storage solutions and ensures compatibility with cloud environments where filesystem access is limited.
Purpose
Many applications need to store dynamic configuration values, user preferences, or temporary settings that cannot be defined in static configuration files. The ValueStore provides a simple, database-backed solution that works reliably across all deployment environments, including Laravel Cloud.Usage
The model provides convenient static methods for managing key-value pairs:Store Values
Retrieve Values
Check if Keys Exist
Remove Values
Data Types
Thevalue column uses JSON casting, which means you can store:
- Strings:
ValueStore::put('name', 'John') - Numbers:
ValueStore::put('count', 42) - Booleans:
ValueStore::put('enabled', true) - Arrays:
ValueStore::put('tags', ['php', 'laravel']) - Objects:
ValueStore::put('config', ['host' => 'localhost', 'port' => 5432])
Migration from Spatie Valuestore
If you’re migrating from Spatie’s filesystem-based Valuestore, the API is largely compatible:Benefits
- Cloud Compatible: Works in environments without persistent filesystem access
- Scalable: Database-backed storage scales with your application
- Atomic: Database transactions ensure data consistency
- Searchable: Can query and filter stored values using Eloquent
- Backup Friendly: Included in regular database backups