alagaccia/laravel-settings
最新稳定版本:v1.5
Composer 安装命令:
composer require alagaccia/laravel-settings
包简介
A Laravel package for managing application settings with a configurable database table
README 文档
README
A Laravel package for managing application settings with a configurable database table.
Installation
Install the package via Composer:
composer require alagaccia/laravel-settings
The service provider will be automatically registered.
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=laravel-settings-config
This will create a config/laravel-settings.php file where you can customize the table name:
return [ 'table_name' => env('SETTINGS_TABLE_NAME', 'settings'), ];
Migration
Publish the migration file:
php artisan vendor:publish --tag=laravel-settings-migrations
Then run the migration:
php artisan migrate
This will create a table (default name: settings) with the following structure:
id- Auto-increment bigint primary keycategory- String(255) with indexlabel- String(255)code- String(255) with unique indexvalue- Long textcreated_at- Timestampupdated_at- Timestamp
Usage
Using the Model
use Alagaccia\LaravelSettings\Models\Setting; // Create a setting Setting::create([ 'category' => 'general', 'label' => 'Site Name', 'code' => 'site_name', 'value' => 'My Awesome Site' ]); // Get a setting by code $siteName = Setting::getByCode('site_name'); // Get a setting with a default value $theme = Setting::getByCode('theme', 'default'); // Set or update a setting Setting::setByCode('site_name', 'New Site Name', 'general', 'Site Name'); // Get all settings in a category $generalSettings = Setting::getByCategory('general');
Using Helper Functions
The package provides convenient global helper functions:
// Get a setting value $siteName = getSetting('site_name'); // Get with default value $theme = getSetting('theme', 'light'); // Set a setting setSetting('site_name', 'New Site Name', 'general', 'Site Name');
Customizing the Table Name
You can customize the table name in the config file or via environment variable:
SETTINGS_TABLE_NAME=app_settings
License
MIT
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-11