LaravelPackages.net
Acme Inc.
Toggle sidebar
utyemma/larasetting

Quick and easy app settings for laravel applications

82
3
v1.08
About utyemma/larasetting

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

Description

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.


Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. Contributing
  5. Maintainers
  6. License

Requirements

  • PHP 8.0+
  • Laravel 9.0+

Installation

  1. Install the package via Composer:

    composer require utyemma/larasettings
    
  2. Publish the migration file:

    php artisan vendor:publish --tag=larasettings-migrations
    
  3. Run the migrations to create the settings table:

    php artisan migrate
    

Usage

Defining a Settings Class

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.

Seeding Settings

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.

Retrieving and Updating Settings

You can interact with settings using dynamic property access or methods:

Retrieving a Setting

$exampleSettings = app(\App\Settings\ExampleSettings::class);
$value = $exampleSettings->some_key; // Retrieve the value of a setting

Updating a Setting

$exampleSettings->some_key = 'New Value'; // Update the value of a setting

Bulk Updating Settings

$exampleSettings->update([
    'key1' => 'Value1',
    'key2' => 'Value2',
]);

Fetching All Settings

$settingsArray = $exampleSettings->toArray();

Strict Mode

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.

Disabling Strict Mode

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;

Contributing

Contributions are welcome! To contribute:

  1. Fork the repository.
  2. Create a feature branch.
  3. Submit a pull request.

Maintainers

  • Utibe-Abasi Emmanuel (GitHub)

License

This package is open-sourced software licensed under the MIT license.

Comments