ahs12/laravel-setanjo
Composer 安装命令:
composer require ahs12/laravel-setanjo
包简介
Laravel settings package for managing application configurations, user preferences, feature flags, and A/B testing with multi-tenant support
关键字:
README 文档
README
A powerful Laravel package for managing application settings and configurations. Store global application settings or model-specific configurations (user preferences, company settings, etc.) with automatic type casting, caching, and a clean API. Perfect for feature flags, A/B testing, user preferences, and dynamic configuration management.
Note: This package does not provide multi-tenancy features for your application. However, if your Laravel project already has multi-tenancy implemented, this package can store tenant-specific settings alongside your existing tenant architecture.
Features
- 🏢 Multi-Tenant Ready: Works with existing multi-tenant applications
- 🗃️ Model-Specific Settings: Store settings for any Eloquent model (User, Company, etc.)
- 🏛️ Global Settings: Application-wide settings without model scope
- ⚡ Caching: Optional caching with configurable cache store
- 🔒 Validation: Validate models and prevent unauthorized access
- 📦 Clean API: Simple, intuitive API for setting and retrieving values
- 🧪 Fully Tested: Comprehensive test suite included
- ✅ Type Safety: Automatic type detection and conversion
Requirements
- PHP 8.2 or higher
- Laravel 10.0 or higher
Installation
- Install the package:
composer require ahs12/laravel-setanjo
- Publish and run migrations:
php artisan vendor:publish --tag="setanjo-migrations"
php artisan migrate
- Configure tenancy mode (optional):
By default, the package runs in strict mode (single tenant model type).
For basic setup with User model, no configuration needed. For other models or multiple tenant types:
php artisan vendor:publish --tag="setanjo-config"
Quick Setup
Option 1: Strict Mode (Default - Single Tenant Type)
Perfect for simple user preferences or single-model tenancy:
// Uses App\Models\User by default // No configuration needed
Option 2: Custom Strict Mode
For using a different model as the single tenant type:
// config/setanjo.php 'tenancy_mode' => 'strict', 'strict_tenant_model' => App\Models\Company::class,
Option 3: Polymorphic Mode
For multiple tenant model types (SaaS apps, complex multi-tenancy):
// config/setanjo.php 'tenancy_mode' => 'polymorphic', 'allowed_tenant_models' => [ App\Models\User::class, App\Models\Company::class, App\Models\Organization::class, ],
Basic Usage
Global Settings
use Ahs12\Setanjo\Facades\Settings; // Set application-wide settings Settings::set('app_name', 'My Application'); Settings::set('maintenance_mode', false); // Get with default fallback $appName = Settings::get('app_name', 'Default Name');
Tenant Settings (Strict Mode)
// User-specific settings (default tenant model) $user = User::find(1); Settings::for($user)->set('theme', 'dark'); Settings::for($user)->set('language', 'en'); // Or by tenant ID Settings::forTenantId(1)->set('notifications', true); echo Settings::for($user)->get('theme'); // 'dark'
Tenant Settings (Polymorphic Mode)
// Different model types as tenants $user = User::find(1); $company = Company::find(1); Settings::for($user)->set('theme', 'dark'); Settings::for($company)->set('timezone', 'UTC'); // Or by tenant ID with model class Settings::forTenantId(1, Company::class)->set('currency', 'USD');
Type Casting
Settings::set('is_active', true); // Boolean Settings::set('max_users', 100); // Integer Settings::set('rate', 4.99); // Float Settings::set('features', ['api', 'sms']); // Array Settings::set('config', '{"theme": "dark", "lang": "en"}'); // JSON string Settings::set('metadata',['version' => '1.0', 'author' => 'John']); // Object // Values are returned with correct types $isActive = Settings::get('is_active'); // Returns boolean true $maxUsers = Settings::get('max_users'); // Returns integer 100 $rate = Settings::get('rate'); // Returns float 4.99 $features = Settings::get('features'); // Returns array ['api', 'sms'] $config = Settings::get('config'); // Returns array ['theme' => 'dark', 'lang' => 'en'] $metadata = Settings::get('metadata'); // Returns object with version and author properties
Common Use Cases
User Preferences
$user = auth()->user(); Settings::for($user)->set('notification_email', true); Settings::for($user)->set('dashboard_layout', 'grid'); Settings::for($user)->set('timezone', 'America/New_York');
Application Configuration
Settings::set('maintenance_mode', false); Settings::set('registration_enabled', true); Settings::set('api_rate_limit', 1000);
Multi-Tenant SaaS (Polymorphic Mode)
// Company-level settings Settings::for($company)->set('feature_api_enabled', true); Settings::for($company)->set('user_limit', 50); // User preferences within company Settings::for($user)->set('email_notifications', false);
Documentation
For detailed documentation, advanced usage, and configuration options, visit our documentation site.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
License
The MIT License (MIT). Please see License File for more information.
ahs12/laravel-setanjo 适用场景与选型建议
ahs12/laravel-setanjo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 459 次下载、GitHub Stars 达 8, 最近一次更新时间为 2025 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「configuration」 「laravel」 「Settings」 「multi-tenant」 「polymorphic」 「feature-flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ahs12/laravel-setanjo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ahs12/laravel-setanjo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ahs12/laravel-setanjo 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Persistent settings package for Laravel framework.
Configuration component
A Zend Framework module to quickly and easily set PHP settings.
Settings Card for Laravel Nova.
Utils to load, parse and work with configuration on Mezzio projects
Extends basic Wordpress features.
统计信息
- 总下载量: 459
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-12