Home

Awesome

ASetting Laravel Package

A2AD6A93-7ED8-4793-BB24-F9CEDDDD45F4-21632-000042AB3BFCB4B4.png

Introduction

ASetting is a Laravel package that allows you to manage settings dynamically in your Laravel applications. With this package, you can organize settings in groups stored in the database, supporting various types of settings for easy management.

Features

Installation

You can add the ASetting package to your Laravel project by following the steps below.

Installation via Composer

Add the package to your project using Composer.

composer require aurorawebsoftware/asetting

Publish Configuration

To publish the configuration file, run the following command:

php artisan vendor:publish --tag=asetting-config

This will add the config/asetting.php file to your project, which contains the configuration settings for the ASetting package.

Migration

Run the migration to create the database table used to store settings:

php artisan migrate

Usage

ASetting Facade

The ASetting Facade allows you to easily manage settings. Below are some basic functions and features provided by the Facade.

group(string $group): self

Used to work with settings in a specific group.

ASetting::group('site')->getValue('title');

groups(array $groups): self

Used to work with settings in multiple groups.

ASetting::groups(['site', 'mail'])->all();

getValue(string $key): int|array|bool|string|null|SettingNotFoundException

Used to get the value of a specific setting.

ASetting::group('site')->getValue('title');

getTitle(string $key): string

Used to get the title of a specific setting.

ASetting::group('site')->getTitle('title');

isVisible(string $key): bool

Used to check the visibility status of a specific setting.

ASetting::group('site')->isVisible('title');

get(string $key): array

Used to get all information about a specific setting.

ASetting::group('site')->get('title');

getValues(array $keys): SettingNotFoundException|array

Used to get the values of a specific setting.

ASetting::group('site')->getValues(['title','name']);

getValues(array $keys): SettingNotFoundException|array

Used to get the values of a specific settings.

ASetting::groups(['site','general'])->getValues(['title','name']);

set(string $key, string|int|bool|array $value, string|null $title = null, bool|null $isVisible = null): bool|array

Used to update or create the value of a specific setting.

ASetting::group('site')->set('title', 'New Title', 'Site Title', true);

delete(string $key): bool|SettingNotFoundException

Used to delete a specific setting.

ASetting::group('site')->delete('title');

all(?string $group = null): array

Used to get all settings grouped by groups or under a specific group.

ASetting::all(); // Get all settings
ASetting::group('site')->all(); // Get all settings under a specific group

destroy(string $group): bool|SettingNotFoundException

Used to delete all settings under a specific group.

ASetting::group('site')->destroy();
ASetting::groups(['site','general'])->destroy();

add(string $group, string $key, string|int|bool|array $value, string $title = null, string $type = 'string', bool $isVisible = null): ASettingModel|SettingNotFoundException

Used to add a new setting.

ASetting::add('site', 'new_setting', 'Value', 'Setting Title', 'string', true);

API Usage

Config

You can define tokens for APIs. You can also configure it by adding your own middleware.

return [
'api_token' => ['YOUR_BEARER_TOKEN_HERE'],
'api_middleware' => [
// YourMiddlewareClass::class
]
];

Endpoint Details

getValue

getTitle

isVisible

get

getValues

set

add

all

delete

destroy

Error Handling

In case of invalid requests or errors, the API will return a JSON response with a corresponding message and, if applicable, validation errors.

Feel free to copy and paste this documentation into your README file. Adjust the formatting as needed.

ASetting Command

This command allows you to interact with the ASetting package.

Usage

php artisan asetting {group=null} {key=null}

This command allows you to interact with the ASetting package.

  1. Fetch a specific setting value:
php artisan asetting myGroup myKey
  1. Fetch all settings in a specific group:
php artisan asetting myGroup
  1. Fetch all settings:
php artisan asetting

Note

License

The ASetting package is licensed under the MIT License.