PHPackages                             camc/lara-settings - 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. [Database &amp; ORM](/categories/database)
4. /
5. camc/lara-settings

ActiveLibrary[Database &amp; ORM](/categories/database)

camc/lara-settings
==================

Abstraction for storing Laravel application settings in the database

v1.3.0(1y ago)0539MITPHPPHP ^8.0

Since May 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/splatEric/lara-settings)[ Packagist](https://packagist.org/packages/camc/lara-settings)[ RSS](/packages/camc-lara-settings/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (5)Used By (0)

LaraSettings
============

[](#larasettings)

[![Latest Stable Version](https://camo.githubusercontent.com/345cbfd78b7a23418ff2b4d3015119d8171c1b9fb90737f4add77c627f705a36/68747470733a2f2f706f7365722e707567782e6f72672f63616d632f6c6172612d73657474696e67732f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/camc/lara-settings)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Tests Action Status](https://camo.githubusercontent.com/b2bfb301a8a099f88e9805816ddec6d7bb05a07a9dc20007b025c85f44992dc6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f73706c6174457269632f6c6172612d73657474696e67732f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/b2bfb301a8a099f88e9805816ddec6d7bb05a07a9dc20007b025c85f44992dc6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f73706c6174457269632f6c6172612d73657474696e67732f72756e2d74657374733f6c6162656c3d7465737473)

This Laravel package provides a simple abstraction for storing application settings in the database. It mimics the basic behaviour of the `config` helper and `Config` facades of core Laravel, but allows the values to be stored in the database where they can be more dynamically managed.

```
Camc\LaraSettings\LaraSetting::create(['key' => 'foo', 'value' => 'bar']);
// with a helper
lara_settings('foo'); // bar
// or with the facade
LaraSettings::get('foo'); // bar
```

An admin interface, or using tools like [Tinkerwell](https://tinkerwell.app) will allow those settings to be updated on any application instance.

```
LaraSettings::set('foo', 'baz');
lara_settings('foo'); // baz
```

Underneath, values are cached to minimise the database hit of retrieving the values.

Dot notation is supported for retrieving values

```
Camc\LaraSettings\LaraSetting::create([
    'key' => 'foo',
    'value' => ['bar' => 'baz']
]);
lara_settings('foo.bar') // baz
```

and a default may be provided to the getter for null values or missing settings:

```
Camc\LaraSettings\Models\LaraSetting::whereKey('foo')->first()->delete();
lara_settings('foo', 'deleted'); // deleted

// a setting instance will be created if not yet defined
LaraSettings::set('foo', null);
lara_settings('foo', 'null value'); // "null value"
```

Testing support
---------------

[](#testing-support)

You can fake the facade in a similar way to other Laravel facades:

```
LaraSettings::fake(['a_fake_key' => 'a fake value']);
```

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

[](#installation)

`composer require camc/lara-settings`

Configuration
-------------

[](#configuration)

Configuration currently supports two settings:

1. `model_table` - defines the name of the table to be used by the `LaraSetting` model. Defaults to `lara_settings_settings`.
2. `cache_key` - the key which caches the settings store. Defaults to `lara-settings`.

The config file can be published via `artisan`:

`php artisan vendor:publish --provider=lara-settings-config`

Usage
-----

[](#usage)

Beyond the examples shown above, seeding settings with initial values may be useful:

```
// database/seeders/settings/default.php
