|
|
8 months ago | |
|---|---|---|
| .. | ||
| AdminControllers | 8 months ago | |
| Commands | 8 months ago | |
| Config | 8 months ago | |
| Enums | 8 months ago | |
| Jobs | 8 months ago | |
| Listeners | 8 months ago | |
| Models | 8 months ago | |
| Providers | 8 months ago | |
| Queues | 8 months ago | |
| Repositorys | 8 months ago | |
| Services | 8 months ago | |
| Tests | 8 months ago | |
| Validations | 8 months ago | |
| Validators | 8 months ago | |
| README.md | 8 months ago | |
Test 模块是一个示例模块,用于展示模块化开发的最佳实践。
app/Module/Test/
├── Models/ # 模型目录
├── Events/ # 事件目录
├── Services/ # 服务目录
│ ├── TestService.php # 基础服务
│ ├── TestServiceInterface.php # 基础服务接口
│ ├── TestStatisticsService.php # 统计服务
│ └── TestStatisticsServiceInterface.php # 统计服务接口
├── Enums/ # 枚举目录
│ └── TestType.php # 测试类型枚举
├── Database/ # 数据库目录
│ └── Migrations/ # 迁移文件
└── Tests/ # 测试目录
运行数据库迁移:
php artisan migrate
use App\Module\Test\Enums\TestType;
// 获取枚举值
$enabled = TestType::ENABLED->value; // 1
$disabled = TestType::DISABLED->value; // 0
// 获取枚举标签
$enabledLabel = TestType::ENABLED->label(); // "启用"
$disabledLabel = TestType::DISABLED->label(); // "禁用"
use App\Module\Test\Services\TestService;
use App\Module\Test\Enums\TestType;
$test = new TestService();
// 创建数据
$model = $test->create([
'name' => '测试数据',
'code' => 'TEST001',
'status' => TestType::ENABLED->value
]);
// 更新数据
$test->update($model, [
'name' => '更新后的数据',
'status' => TestType::DISABLED->value
]);
// 删除数据
$test->delete($model);
use App\Module\Test\Services\TestStatisticsService;
use App\Module\Test\Enums\TestType;
$statistics = new TestStatisticsService();
// 获取总数统计
$totals = $statistics->getTotalStatistics();
// 获取状态分布
$statusDistribution = $statistics->getStatusDistribution();
// 获取每日创建数量统计
$dailyStats = $statistics->getDailyCreationStatistics(7);
暂无配置项。
运行测试:
php artisan test app/Module/Test/Tests