Laravel Setting
Easily save, update and get titles, descriptions, and more. it is very easy to use.
This is great for storing and receiving general site information.
Installation
requires PHP 8+ and Laravel 9+
via composer:
$ composer require RanjbarAli/Laravel-Setting
If you do not run Laravel 5.5 (or higher), then add the service provider in config/app.php
:
RanjbarAli\LaravelSetting\LaravelSettingServiceProvider::class,
You can publish migration and configuration with:
php artisan vendor:publish --provider="RanjbarAli\LaravelSetting\LaravelSettingServiceProvider"
Migrate:
php artisan migrate
Usage
Initialize
setting()
Get All (array)
setting()->value
Get One (string | array | integer | float | boolean)
setting('key')->value
Get Multiple (array)
setting(['key1', 'key2'])->value
Update (boolean)
setting('key')->set('new value')
Add (boolean)
setting()->add($key, $value, $type)
Type must be one of "string"
, "array"
, "boolean"
, "integer"
, "float"
default: "string"
Delete (boolean)
setting('key')->delete()
Check Value (boolean)
setting('key')->is('value')
Check Value with Type (boolean)
setting('key')->is_exactly('value')
Check Exists (boolean)
setting('key')->exists()
Recache
setting()->restart()
Examples
add() : Add and Get One
setting()->add('key', 'value');
setting('key')->value; // Output: 'value'
set()
setting()->add('key', 'old value');
setting('key')->set('new value');
setting('key')->value; // Output: 'new value'
Get Multiple
setting()->add('key1', 'foo');
setting()->add('key2', 'bar');
setting(['key1', 'key2'])->value; // Output: [ 'key1' => 'foo', 'key2' => 'bar' ]
is()
setting()->add('key', '1');
setting('key')->is(1); // Output: true
is_exactly()
setting()->add('key', '1');
setting('key')->is_exactly(1); // Output: false
exists()
setting()->add('key', 'value');
setting('key')->delete();
setting('key')->exists(); // Output: false
in blade:
"><title> {{ setting('title')->value }} title> <meta name="description" content=" {{ setting('description')->value }} " />