overtrue / laravel-skeleton
A Laravel starter project template.
Fund package maintenance!
overtrue
Requires
- php: ^8.1.1
- ext-json: *
- guzzlehttp/guzzle: ^7.2
- kra8/laravel-snowflake: ^2.2
- laravel/framework: ^10.0
- laravel/sanctum: ^3.0.1
- laravel/tinker: ^2.7
- predis/predis: ^2.0.0
- tucker-eric/eloquentfilter: *
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.13
- brainmaestro/composer-git-hooks: dev-master
- fakerphp/faker: ^1.9.1
- laravel/pint: ^1.1.1
- mockery/mockery: ^1.4.4
- nunomaduro/collision: ^7.7
- phpunit/phpunit: ^10.2.3
- dev-master
- 4.0.2
- 4.0.1
- 4.0.0
- 3.0.0
- 2.0.3
- 2.0.1
- 2.0.0
- 1.0.0
- dev-dependabot/composer/laravel/framework-10.47.0
- dev-dependabot/composer/barryvdh/laravel-ide-helper-3.0.0
- dev-dependabot/composer/phpunit/phpunit-10.5.11
- dev-dependabot/composer/laravel/pint-1.14.0
- dev-dependabot/composer/tucker-eric/eloquentfilter-3.3.0
- dev-dependabot/composer/laravel/tinker-2.9.0
- dev-dependabot/composer/fakerphp/faker-1.23.1
- dev-dependabot/composer/laravel/sanctum-3.3.3
- dev-dependabot/composer/mockery/mockery-1.6.7
- dev-feat/ddd
This package is auto-updated.
Last update: 2024-11-05 22:51:34 UTC
README
开箱即用的 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
内置接口
用户登录(获取 token)
POST /api/auth/login
- Request (
application/json
)
{ "username": "admin", "password": "changeThis!!" }
- Response 200 (application/json)
{ "type": "bearer", "token":"oVFV407i4jSTxjFO2tNxzh8lDaxVLbIkZZiDwjgMSYhvvkbUUXw8y0XgeYtxLAp4paznq0oxSMDdXmco" }
用户注册
POST /api/auth/register
- Request (
application/json
)
{ "username": "demo", "password": "123456" }
- Response 200 (
application/json
)
{ "type": "bearer", "token":"oVFV407i4jSTxjFO2tNxzh8lDaxVLbIkZZiDwjgMSYhvvkbUUXw8y0XgeYtxLAp4paznq0oxSMDdXmco" }
登出
POST /api/auth/logout
- Request (
application/json
) + Headers
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1...
- Response 204
获取当前登录用户
GET /api/me
- 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 }
❤️ Sponsor me
If you like the work I do and want to support it, you know what to do ❤️
如果你喜欢我的项目并想支持它,点击这里 ❤️
Project supported by JetBrains
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
License
MIT