Skip to content

Adds settings to Laravel that are stored within a Database

Notifications You must be signed in to change notification settings

LaraPKG/laravel-settings

Repository files navigation

LaraPKG Laravel Settings

PHP Unit Tests Psalm PHP CS Fixer

Adds simple settings to any Laravel application.

Usage

Types

Define setting types in config/laravel-settings.php, these are simply stored along with each setting.

Casts

Define type casts in the above config file, setting values will automatically be casted to their native types on retrieval!

return [
    // ...
    'casts' => [
        'boolean' => 'bool',
        'select' => 'array',
        'json' => 'json',
        'number' => 'int',
    ],
    // ...
];

Retrieving a setting value

  • Using the helper
setting('setting_group.key');
  • Using the facade
\LaraPkg\Settings\Facades\Setting::get('setting_group.key');
  • With an Entity id An entity id allows you to store specific settings for that entity (such as a Domain or multi-tenant application)
$entityId = 1;
\LaraPkg\Settings\Facades\Setting::get('setting_group.key', $entityId);

Setting a setting

  • Using the helper
set_setting('setting_group.key', 'Some value!');
  • Using the Facade
$value = 'something to store';
$entityId = 1 ?? null;
$groupName = 'setting_group' ?? null;
\LaraPkg\Settings\Facades\Setting::set('key', $value, $groupName, $entityId);

Installation

composer require larapkg/laravel-settings
php artisan vendor:publish --provider="LaraPkg\Settings\SettingsServiceProvider"

About

Adds settings to Laravel that are stored within a Database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages