开箱即用的 Laravel API 基础结构。
🚨自己用的哈,仅供参考,不提供咨询解答服务。
- DDD(领域模型驱动)结构;
- 内置生成器,一键生成模块;
- 内置 laravel/sanctum 的授权机制;
- 高度完善的控制器、模型、模块模板;
- 集成常用基础扩展;
- 内置模型通用高阶 Traits 封装;
- 自动注册 Policies;
- 内置用户系统和基础接口;
- 内置管理后台接口;
- 创建项目
$ composer create-project overtrue/laravel-skeleton -vvv
- 创建配置文件
$ cp .env.example .env
- 创建数据表和测试数据
$ php artisan migrate --seed
这一步将会创建管理员账号
username:admin / password:changeThis!!
和一个 demo 设置项。
然后访问 http://laravel-skeleton.test/api/settings
将会看到演示的设置项信息。
php artisan make:domain Post
该命令将会创建
domain/Post
目录,包含Actions
,Models
,Policies
,Filters
等目录。
所有官方的生成命令都增加了 -d
参数,用于指定领域名称,例如:
php artisan make:model Post -d Post
另外,还有一些自定义的生成命令:
php artisan make:action MarkPostAsDraft -d Post
php artisan make:app Post
php artisan make:endpoint GetPost -a Post
php artisan make:middleware MustBePublished -a Post
php artisan make:request CreatePost -a Post
php artisan make:resource Post -a Post
- Request (
application/json
)
{
"username": "admin",
"password": "changeThis!!"
}
- Response 200 (application/json)
{
"type": "bearer",
"token":"oVFV407i4jSTxjFO2tNxzh8lDaxVLbIkZZiDwjgMSYhvvkbUUXw8y0XgeYtxLAp4paznq0oxSMDdXmco"
}
- Request (
application/json
)
{
"username": "demo",
"password": "123456"
}
- Response 200 (
application/json
)
{
"type": "bearer",
"token":"oVFV407i4jSTxjFO2tNxzh8lDaxVLbIkZZiDwjgMSYhvvkbUUXw8y0XgeYtxLAp4paznq0oxSMDdXmco"
}
- Request (
application/json
) Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1...
- Response 204
- Request (
application/json
) Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1...
- Response 200 (
application/json
)
{
"id": 1,
"username": "admin",
"nickname": "超级管理员",
"avatar": "\/img\/default-avatar.png",
"email": null,
"gender": "none",
"phone": null,
"birthday": null,
"settings": [],
"is_admin": true,
"last_active_at": null,
"last_refreshed_at": null,
"banned_at": null,
"email_verified_at": null,
"created_at": "2020-03-17T09:37:45.000000Z",
"updated_at": "2020-03-17T09:37:45.000000Z",
"deleted_at": null
}
If you like the work I do and want to support it, you know what to do ❤️
如果你喜欢我的项目并想支持它,点击这里 ❤️
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
MIT