settings-system

仓库创建 2026年7月4日最近提交 21 天前SkillHot 收录 21 天前
▸ 精选理由

统一配置读写并处理租户与全局回退的常见场景。

▸ 风险提示

涉及数据库和加密示例,修改前需注意权限与备份。

这个 Skill 做什么

在多租户 Laravel 应用中管理多态设置及全局回退链。

在多租户 Laravel 应用里把配置按机构分开存,又能回退到全局默认,支持多态存储和 agency → 全局 的回退链。用于读写 App\\Models\\Setting 和 App\\Enumerations\\SettingType 的记录,方便把每个租户的第三方凭证或集成配置(比如 Xero、Stripe)单独保存。特别适合需要按租户定制配置同时保留系统默认的场景。

▸ 展开 SKILL.md 英文原文

Multi-tenant polymorphic settings system with agency-scoped records and global fallback chain. Create, read, update settings records. Use when working with App\Models\Setting, App\Enumerations\SettingType, the settings table migration, the polymorphic settings system, or the fallback chain (agency-specific → global default). Also use when integrating third-party services (Xero, Stripe, etc.) that need per-agency configuration storage.

垂直行业多租户设置回退链Laravel通用
0
Stars
0
Forks
23
仓库内 Skill
+0
7 日增星
安装 / 使用
给你的 Agent 一句话(通用)
帮我安装这个 skill:https://raw.githubusercontent.com/ceilidhboy/skills/master/skills/settings-system/SKILL.md
或 curl 直取 SKILL.md
curl -fsSL "https://raw.githubusercontent.com/ceilidhboy/skills/master/skills/settings-system/SKILL.md"
SKILL.MD 节选查看完整文件 ↗
# Settings System

## Quick Start

```php
use App\Enumerations\SettingType;

// Create a settings record (globally, for the system agency)
Setting::create([
    'agency_id' => Agency::SystemAgencyId,
    'type' => SettingType::XeroIntegration,
    'data' => ['key' => encrypt('value')],
]);

// Read with fallback chain (agency → global)
$setting = Setting::forAgency($agencyId, SettingType::XeroIntegration);
$data = $setting?->data;
```

## Model

`App\Models\Setting` extends `TenantModel`. Key details:

- `data` column is JSON, cast to `array` on read
- `$guarded = []` — all fields mass-assignable
- `TenantModel` auto-populates `agency_id` on create via `AgencyScoping` trait (can override by 
via SKILL·HOT · 数据来自 GitHub 公开信息 · 原文版权归作者所有