Quick and easy app settings for laravel applications
utyemma/larasetting is a Laravel package for quick and easy app settings for laravel applications.
It currently has 3 GitHub stars and 82 downloads on Packagist (latest version v1.08).
Install it with composer require utyemma/larasetting.
Discover more Laravel packages by utyemma
or browse all Laravel packages to compare alternatives.
Last updated
LaraSettings is a Laravel package that simplifies the management of application settings. It provides a structured and extensible way to define, retrieve, and update settings stored in the database. It includes useful commands for generating and seeding settings classes, making it easy to customize for various use cases.
Install the package via Composer:
composer require utyemma/larasettings
Publish the migration file:
php artisan vendor:publish --tag=larasettings-migrations
Run the migrations to create the settings table:
php artisan migrate
Use the make:setting command to create a new settings class:
php artisan make:setting ExampleSettings
This will generate a new settings class in the App\Settings namespace. Define your options, labels, and casts within the class to tailor it to your application's needs.
To seed settings into the database, use the settings:seed command:
php artisan settings:seed --class=ExampleSettings
Replace ExampleSettings with the name of your settings class. This will populate the database with the default attributes and values defined in the class.
You can interact with settings using dynamic property access or methods:
$exampleSettings = app(\App\Settings\ExampleSettings::class);
$value = $exampleSettings->some_key; // Retrieve the value of a setting
$exampleSettings->some_key = 'New Value'; // Update the value of a setting
$exampleSettings->update([
'key1' => 'Value1',
'key2' => 'Value2',
]);
$settingsArray = $exampleSettings->toArray();
LaraSettings operates in strict mode by default. Strict mode ensures that only settings defined in the options array of a settings class can be updated or created. This prevents accidental changes to undefined settings. When enabled, attempting to update an undefined setting will throw an exception. Ensure that all valid keys are listed in the options array of your settings class.
If you want to allow dynamic creation of settings that are not predefined in the options array, you can set the $strict property to false in your settings class:
protected $strict = false;
Contributions are welcome! To contribute:
This package is open-sourced software licensed under the MIT license.