Download the PHP package weijukeji/laravel-dictionary without Composer
On this page you can find all versions of the php package weijukeji/laravel-dictionary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download weijukeji/laravel-dictionary
More information about weijukeji/laravel-dictionary
Files in weijukeji/laravel-dictionary
Download weijukeji/laravel-dictionary
More information about weijukeji/laravel-dictionary
Files in weijukeji/laravel-dictionary
Vendor weijukeji
Package laravel-dictionary
Short Description Laravel Dictionary package for managing dictionary categories and items with caching support
License MIT
Package laravel-dictionary
Short Description Laravel Dictionary package for managing dictionary categories and items with caching support
License MIT
Please rate this library. Is it a good library?
Informations about the package laravel-dictionary
Laravel Dictionary
一个功能完整、易于使用的 Laravel 字典管理包,支持分类和字典项的统一管理,内置缓存优化,提供 RESTful API 接口。
简体中文
特性
- ✨ 分类管理 - 支持字典分类的树形结构管理
- 📝 字典项管理 - 灵活的字典项增删改查
- 🔢 自动生成值 - 支持自动生成字典项数值
- ⚡ 高性能 - 内置缓存支持,优化查询性能
- 🔌 即插即用 - 开箱即用的 API 接口
- 🎯 RESTful 风格 - 标准的 RESTful API 设计
- 📦 易于扩展 - 清晰的代码结构,方便二次开发
- 🔒 数据过滤 - 集成 EloquentFilter 支持复杂查询
- 🌱 数据导入导出 - 支持导出和导入种子数据
- 🗄️ 多数据库支持 - 支持 MySQL、PostgreSQL、SQLite 等
环境要求
- PHP >= 8.2
- Laravel 11.x, 12.x, 13.x
安装
通过 Composer 安装包:
发布配置文件和迁移文件:
运行数据库迁移:
配置
配置文件位于 config/dictionary.php:
使用指南
API 端点
包提供了完整的 RESTful API 接口:
字典分类
字典项
请求示例
创建字典分类
创建字典项(手动输入键)
创建字典项(自动生成键)
获取字典项
自动生成字典键
创建字典项时,可以选择自动生成数字键:
生成示例:
- 首次创建:生成
"1" - 已有
"1", "2", "3":生成"4" - 已有
"1", "active", "99":生成"100"(忽略非数字键)
在代码中使用
使用 Facade
使用模型
使用服务类
数据导入导出
导出字典数据
将当前数据库中的字典数据导出为 JSON 文件:
导入字典数据
从 JSON 文件导入字典数据:
在 DatabaseSeeder 中使用
JSON 文件格式
数据结构
字典分类表 (dictionary_categories)
| 字段 | 类型 | 说明 |
|---|---|---|
| id | bigint | 主键 |
| parent_id | bigint | 父分类ID |
| category_key | string | 分类键(唯一) |
| category_name | string | 分类名称 |
| sort_order | integer | 排序 |
| created_at | timestamp | 创建时间 |
| updated_at | timestamp | 更新时间 |
字典项表 (dictionary_items)
| 字段 | 类型 | 说明 |
|---|---|---|
| id | bigint | 主键 |
| parent_key | string | 所属分类键 |
| item_key | string | 字典项键 |
| item_value | string | 字典项值 |
| sort_order | integer | 排序 |
| is_enabled | boolean | 是否启用 |
| created_at | timestamp | 创建时间 |
| updated_at | timestamp | 更新时间 |
响应格式
所有 API 接口返回统一的 JSON 格式:
成功响应
错误响应
数据保护
删除保护
- ❌ 不能删除有子分类的分类
- ❌ 不能删除有字典项的分类
- ✅ 必须先清空数据才能删除
唯一性约束
- 分类键(category_key)全局唯一
- 字典项键(item_key)在同一分类下唯一
命令行工具
| 命令 | 说明 |
|---|---|
dictionary:export [path] |
导出字典数据到 JSON 文件 |
dictionary:reseed [--force] |
清空并重新导入字典数据 |
测试
更新日志
请查看 CHANGELOG 了解更多信息。
贡献
欢迎贡献代码!请查看 CONTRIBUTING 了解详情。
安全
如果发现任何安全相关问题,请发送邮件至 [email protected] 而不是使用 issue 跟踪器。
许可证
MIT 许可证。详情请查看 LICENSE 文件。
致谢
- 基于 Laravel 框架开发
- 使用 EloquentFilter 进行数据过滤
All versions of laravel-dictionary with dependencies
PHP Build Version
Package Version
Requires
php Version
^8.2
illuminate/support Version ^11.0 || ^12.0 || ^13.0
tucker-eric/eloquentfilter Version ^3.5
illuminate/support Version ^11.0 || ^12.0 || ^13.0
tucker-eric/eloquentfilter Version ^3.5
The package weijukeji/laravel-dictionary contains the following files
Loading the files please wait ...