PHPackages                             spatie/laravel-valuestore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. spatie/laravel-valuestore

ActiveLibrary[Caching](/categories/caching)

spatie/laravel-valuestore
=========================

Easily store some values

1.3.3(1y ago)7691.2k↓94.1%47MITPHPPHP ^8.0|^8.1CI passing

Since Apr 5Pushed 9mo ago11 watchersCompare

[ Source](https://github.com/spatie/valuestore)[ Packagist](https://packagist.org/packages/spatie/laravel-valuestore)[ Docs](https://github.com/spatie/valuestore)[ Fund](https://spatie.be/open-source/support-us)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-valuestore/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (1)Versions (15)Used By (0)

Easily store some loose values
==============================

[](#easily-store-some-loose-values)

[![Latest Version on Packagist](https://camo.githubusercontent.com/973d6a7b6b9ac8fd4301f89efcd877e7eca07830d31357ea688261e6432d12bf/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f76616c756573746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/valuestore)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Tests](https://github.com/spatie/valuestore/workflows/Tests/badge.svg)](https://github.com/spatie/valuestore/workflows/Tests/badge.svg)[![Total Downloads](https://camo.githubusercontent.com/f4a81f7c24c5bc66d06fe25a232955361b64eea606b413f3204da30d8ea42132/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f76616c756573746f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/valuestore)

This package makes it easy to store and retrieve some loose values. Stored values are saved as a json file.

It can be used like this:

```
use Spatie\Valuestore\Valuestore;

$valuestore = Valuestore::make($pathToFile);

$valuestore->put('key', 'value');

$valuestore->get('key'); // Returns 'value'

$valuestore->has('key'); // Returns true

// Specify a default value for when the specified key does not exist
$valuestore->get('non existing key', 'default') // Returns 'default'

$valuestore->put('anotherKey', 'anotherValue');

// Put multiple items in one go
$valuestore->put(['ringo' => 'drums', 'paul' => 'bass']);

$valuestore->all(); // Returns an array with all items

$valuestore->forget('key'); // Removes the item

$valuestore->flush(); // Empty the entire valuestore

$valuestore->flushStartingWith('somekey'); // remove all items whose keys start with "somekey"

$valuestore->increment('number'); // $valuestore->get('number') will return 1
$valuestore->increment('number'); // $valuestore->get('number') will return 2
$valuestore->increment('number', 3); // $valuestore->get('number') will return 5

// Valuestore implements ArrayAccess
$valuestore['key'] = 'value';
$valuestore['key']; // Returns 'value'
isset($valuestore['key']); // Return true
unset($valuestore['key']); // Equivalent to removing the value

// Valuestore implements Countable
count($valuestore); // Returns 0
$valuestore->put('key', 'value');
count($valuestore); // Returns 1
```

Read the [usage](#usage) section of this readme to learn about the other methods.

In [this post on Laravel News](https://laravel-news.com/global-application-settings), [Tim MacDonald](https://twitter.com/timacdonald87) shares how you can use this package to power a `settings` function.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/71a003bd7676304528f3007d6850958c80bdb75a961804042653056cbdbf306e/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f76616c756573746f72652e6a70673f743d31)](https://spatie.be/github-ad-click/valuestore)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/valuestore
```

Usage
-----

[](#usage)

To create a Valuestore use the `make` method.

```
$valuestore = Valuestore::make($pathToFile);
```

You can also pass some values as a second argument. These will be added to the valuestore using the `put` method.

```
$valuestore = Valuestore::make($pathToFile, ['key' => 'value']);
```

All values will be saved as json in the given file.

When there are no values stored, the file will be deleted.

You can call the following methods on the `Valuestore`

### put

[](#put)

```
/**
 * Put a value in the store.
 *
 * @param string|array $name
 * @param string|int|null $value
 *
 * @return $this
 */
public function put($name, $value = null)
```

### get

[](#get)

```
/**
 * Get a value from the store.
 *
 * @param string $name
 *
 * @return null|string
 */
public function get(string $name)
```

### has

[](#has)

```
/*
 * Determine if the store has a value for the given name.
 */
public function has(string $name) : bool
```

### all

[](#all)

```
/**
 * Get all values from the store.
 *
 * @return array
 */
public function all() : array
```

### allStartingWith

[](#allstartingwith)

```
/**
 * Get all values from the store which keys start with the given string.
 *
 * @param string $startingWith
 *
 * @return array
*/
public function allStartingWith(string $startingWith = '') : array
```

### forget

[](#forget)

```
/**
 * Forget a value from the store.
 *
 * @param string $key
 *
 * @return $this
 */
public function forget(string $key)
```

### flush

[](#flush)

```
/**
 * Flush all values from the store.
 *
 * @return $this
 */
 public function flush()
```

### flushStartingWith

[](#flushstartingwith)

```
/**
 * Flush all values from the store which keys start with the specified value.
 *
 * @param string $startingWith
 *
 * @return $this
 */
 public function flushStartingWith(string $startingWith)
```

### pull

[](#pull)

```
/**
 * Get and forget a value from the store.
 *
 * @param string $name
 *
 * @return null|string
 */
public function pull(string $name)
```

### increment

[](#increment)

```
/**
 * Increment a value from the store.
 *
 * @param string $name
 * @param int $by
 *
 * @return int|null|string
 */
 public function increment(string $name, int $by = 1)
```

### decrement

[](#decrement)

```
/**
 * Decrement a value from the store.
 *
 * @param string $name
 * @param int $by
 *
 * @return int|null|string
 */
 public function decrement(string $name, int $by = 1)
```

push
----

[](#push)

```
/**
 * Push a new value into an array.
 *
 * @param string $name
 * @param $pushValue
 *
 * @return $this
 */
public function push(string $name, $pushValue)
```

prepend
-------

[](#prepend)

```
/**
 * Prepend a new value into an array.
 *
 * @param string $name
 * @param $prependValue
 *
 * @return $this
 */
public function prepend(string $name, $prependValue)
```

count
-----

[](#count)

```
/**
 * Count elements.
 *
 * @return int
 */
public function count()
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information about what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#postcardware)

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Jolita Grazyte](https://github.com/JolitaGrazyte)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance49

Moderate activity, may be stable

Popularity41

Moderate usage in the ecosystem

Community27

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 67.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~269 days

Recently: every ~384 days

Total

13

Last Release

506d ago

Major Versions

0.0.1 → 1.0.02016-04-06

PHP version history (5 changes)0.0.1PHP ^7.0

1.2.3PHP ^7.2

1.2.5PHP ^7.3|^8.0

1.3.0PHP ^7.3|^8.0|^8.1

1.3.1PHP ^8.0|^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (82 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![riasvdv](https://avatars.githubusercontent.com/u/3626559?v=4)](https://github.com/riasvdv "riasvdv (6 commits)")[![chapeupreto](https://avatars.githubusercontent.com/u/834048?v=4)](https://github.com/chapeupreto "chapeupreto (4 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (4 commits)")[![timacdonald](https://avatars.githubusercontent.com/u/24803032?v=4)](https://github.com/timacdonald "timacdonald (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![introwit](https://avatars.githubusercontent.com/u/11228182?v=4)](https://github.com/introwit "introwit (2 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (2 commits)")[![thijsvdanker](https://avatars.githubusercontent.com/u/429548?v=4)](https://github.com/thijsvdanker "thijsvdanker (1 commits)")[![kudashevs](https://avatars.githubusercontent.com/u/15892462?v=4)](https://github.com/kudashevs "kudashevs (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (1 commits)")[![ArroWsGM](https://avatars.githubusercontent.com/u/9962071?v=4)](https://github.com/ArroWsGM "ArroWsGM (1 commits)")[![apiv-thomas](https://avatars.githubusercontent.com/u/53090992?v=4)](https://github.com/apiv-thomas "apiv-thomas (1 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (1 commits)")[![carusogabriel](https://avatars.githubusercontent.com/u/16328050?v=4)](https://github.com/carusogabriel "carusogabriel (1 commits)")[![hedii](https://avatars.githubusercontent.com/u/5358048?v=4)](https://github.com/hedii "hedii (1 commits)")

---

Tags

cachejsonphpvaluestorejsonspatievaluestore

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-valuestore/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-valuestore/health.svg)](https://phpackages.com/packages/spatie-laravel-valuestore)
```

###  Alternatives

[spatie/valuestore

Easily store some values

7751.1M56](/packages/spatie-valuestore)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[spatie/once

A magic memoization function

1.4k29.9M102](/packages/spatie-once)[spatie/blink

Cache that expires in the blink of an eye

1675.6M11](/packages/spatie-blink)[spatie/laravel-varnish

Making Varnish and Laravel play nice together

417244.8k3](/packages/spatie-laravel-varnish)[spatie/laravel-blink

Cache that expires in the blink of an eye

1631.2M10](/packages/spatie-laravel-blink)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
