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

Setting Laravel Package

larapacks/setting

Lightweight Laravel settings manager that stores and retrieves key/value app configuration at runtime. Provides a clean API and helpers for persisting settings (including grouped/namespaced keys), with caching support for fast reads and easy integration into Laravel apps.

View on GitHub
Deep Wiki
Context7

Setting

Build Status Scrutinizer Code Quality Total Downloads Latest Stable Version License

Description

Setting is an easy, encrypted & cached, database key => value store for your laravel application.

Requirements

  • PHP >= 7.2
  • Laravel >= 6.0

Installation

Run the following command:

composer require larapacks/setting

Note: The service provider and Setting facade are registered automatically.

Once that's complete, publish the migration and configuration file using:

php artisan vendor:publish --tag="setting"

Then run php artisan migrate.

Usage

Note: All usage below can be accessed via the helper method setting().

Setting a value:

Setting::set('key', 'value');

Setting multiple values:

Setting::set([
    'key.1' => 'value',
    'key.2' => 'value',
    'key.3' => 'value',
]);

Retrieving a value:

$value = Setting::get('key.1');

dd($value); // Returns 'value'

Retrieving a value or return default value if it doesn't exist:

$value = Setting::get('non-existent-key', 'default');

dd($value); // Returns 'default'

Retrieving the Setting model for a particular key:

$model = Setting::find('key.1');

dd($model); // Reurns instance of Model (your configured model).

Retrieving all keys with values:

Setting::set([
    'key.1' => 'value',
    'key.2' => 'value',
    'key.3' => 'value',
]);

$settings = Setting::all();

dd($settings);

// Returns:
// array [
//  'key.1' => 'value',
//  'key.2' => 'value',
//  'key.3' => 'value',
// ]

Retrieving the your configured Setting model:

$model = Setting::model();

$setting = new $model();

$setting->key = 'key';
$setting->value = 'value';

$setting->save();

Determining if a setting exists:

if (Setting::has('key')) {
    // The setting exists.
}

Flipping a boolean setting:

Setting::set('notifications', true);

// Disable notifications.
Setting::flip('notifications');

dd(Setting::get('notifications')); // Returns false.

// Enable notifications.
Setting::flip('notifications');

dd(Setting::get('notifications')); // Returns true.

// Default flip setting:
Setting::flip('new-key');

dd(Setting::get('new-key')); // Retuns true.

Enabling a boolean setting:

Setting::set('notifications', false);

Setting::enable('notifications');

dd(Setting::get('notifications')); // Returns true.

Disabling a boolean setting:

Setting::set('notifications', true);

Setting::disable('notifications');

dd(Setting::get('notifications')); // Returns false.

Using your own model

To use your own model, change the model configuration option in your config/settings.php file.

When you create your own model, be sure to include the trait: Larapacks\Setting\Traits\SettingTrait:

namespace App;

use Larapacks\Setting\Traits\SettingTrait;

class Setting extends Model
{
    use SettingTrait;
}

Encryption

Encryption can be enabled or disabled in the published configuration file. By default, it is enabled.

Encryption is performed by laravel's included helper methods encrypt() and decrypt().

You can enable or disable encryption at any time, however upon disabling encryption you will receive the raw encrypted string for settings that have previously been encrypted.

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui