Download the PHP package bleuren/laravel-settings without Composer
On this page you can find all versions of the php package bleuren/laravel-settings. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package laravel-settings
Laravel Settings
一個現代化、高性能的 Laravel 設定管理套件
透過資料庫存儲應用設定,支援智能緩存、自定義模型和依賴注入
✨ 功能特點
- 🗄️ 資料庫存儲 - 在資料庫中安全存儲設定,支援複雜資料類型
- ⚡ 智能緩存 - 多層緩存策略:Laravel 緩存 + 記憶化緩存
- 🔧 Contract 驅動 - 基於
SettingRepository
Contract,支援依賴注入 - 🎯 自定義模型 - 完全支援自定義 Eloquent 模型和欄位
- 📦 批量操作 - 高效的批量設定操作,支援資料庫事務
- 🚀 預載入功能 - 可配置的常用設定預載入,提升性能
- 🛠️ 命令行工具 - 提供緩存管理和維護命令
- 🧪 完整測試 - 106 個測試,229 個斷言,確保穩定性
- 📋 Laravel 慣例 - 完全符合 Laravel 設計模式和最佳實踐
📋 系統需求
- PHP 8.3+
- Laravel 11.0+ 或 12.0+
🚀 安裝
透過 Composer 安裝套件:
發布並執行遷移:
(可選)發布配置文件:
📖 基本使用
Facade 方式(推薦)
輔助函數
依賴注入方式
🎨 自定義模型
創建自定義設定模型
配置自定義模型
使用自定義模型
📚 API 參考
SettingRepository Contract
方法 | 描述 | 返回類型 |
---|---|---|
get(string $key, mixed $default = null) |
獲取設定值 | mixed |
set(string $key, mixed $value, ?string $description = null) |
設置設定值 | Model |
setMany(array $settings, ?string $description = null) |
批量設置設定 | Collection |
has(string $key) |
檢查設定是否存在 | bool |
remove(string $key) |
刪除設定 | bool |
all() |
獲取所有設定 | Collection |
search(string $pattern) |
搜索設定(支援 SQL LIKE) | Collection |
clearMemoryCache() |
清除記憶體緩存 | void |
cacheKey(string $key) |
獲取緩存鍵名 | string |
getModel() |
獲取模型實例 | Model |
HasSettings Trait 方法
Trait 方法 | 靜態別名 | 描述 |
---|---|---|
getSetting($key, $default) |
get() |
獲取設定值 |
setSetting($key, $value, $desc) |
set() |
設置設定值 |
setManySettings($settings, $desc) |
setMany() |
批量設置 |
hasSetting($key) |
has() |
檢查設定存在 |
removeSetting($key) |
remove() |
刪除設定 |
getAllSettings() |
all() |
獲取所有設定 |
searchSettings($pattern) |
search() |
搜索設定 |
⚙️ 配置選項
🚀 高級功能
預載入設定
提升應用啟動性能,預載入常用設定:
緩存管理
批量操作最佳實踐
搜索和過濾
🏗️ 架構設計
設計模式
- Contract Pattern - 基於
SettingRepository
介面 - Repository Pattern - 抽象資料存取層
- Service Provider Pattern - Laravel 服務註冊
- Facade Pattern - 簡潔的靜態介面
- Trait Pattern - 可重用的功能模組
緩存策略
- Laravel 緩存 - 使用
Cache::rememberForever()
永久緩存 - 記憶化緩存 - 請求期間的記憶體緩存
- 模型隔離 - 不同模型使用獨立緩存空間
- 智能失效 - 資料更新時自動清除相關緩存
依賴注入
🧪 測試
執行完整測試套件:
測試覆蓋範圍
- ✅ 106 個測試,229 個斷言
- ✅ Contract 和依賴注入測試
- ✅ 緩存機制測試
- ✅ 自定義模型測試
- ✅ 批量操作測試
- ✅ 錯誤處理測試
- ✅ 整合測試
🔧 遷移指南
從其他設定套件遷移
如果您正在使用其他設定套件,可以輕鬆遷移:
資料庫結構
預設的設定表結構:
📄 授權
本套件基於 MIT 授權條款 開源。
All versions of laravel-settings with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.3
illuminate/support Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
The package bleuren/laravel-settings contains the following files
Loading the files please wait ....