rcrosbourne / blueprint
一个表达性、易于阅读的代码生成工具。
Requires
- doctrine/dbal: ^3.3
- illuminate/console: ^10.0
- illuminate/filesystem: ^10.0
- illuminate/support: ^10.0
- laravel-shift/faker-registry: ^0.3.0
- symfony/yaml: >=6.2
Requires (Dev)
- laravel/pint: ^1.2
- mockery/mockery: ^1.4.4
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.0
Suggests
- jasonmccreary/laravel-test-assertions: Required to use additional assertions in generated tests (^1.0).
This package is auto-updated.
Last update: 2024-09-06 17:55:46 UTC
README
Blueprint 是一个开源工具,可以从一个单一的、易于阅读的定义中快速生成多个 Laravel 组件。
观看 Blueprint 的快速演示,然后继续阅读以开始使用。
要求
Blueprint 需要运行最新稳定版本的 Laravel 的 Laravel 应用程序,目前是 Laravel 10.x。
安装
您可以使用以下命令通过 composer 安装 Blueprint
composer require -W --dev laravel-shift/blueprint
Blueprint 将自动使用 package discovery 进行注册。
附加配置:如果您正在运行 Laravel 8,或者注册基于类的路由或使用 app/Models
文件夹,您将需要配置 Blueprint。请参阅 Blueprint 文档 以获取更多指导。
基本用法
Blueprint 附带一组 artisan 命令。您最常使用的命令是用于生成 Laravel 组件的 blueprint:build
命令
php artisan blueprint:build [draft]
draft 文件包含要生成的组件的 定义。
让我们回顾以下示例 draft 文件以生成一些 blog 组件
models: Post: title: string:400 content: longtext published_at: nullable timestamp author_id: id:user controllers: Post: index: query: all render: post.index with:posts store: validate: title, content, author_id save: post send: ReviewPost to:post.author.email with:post dispatch: SyncMedia with:post fire: NewPost with:post flash: post.title redirect: post.index
从这些简单的 20 行 YAML 中,Blueprint 将生成以下所有 Laravel 组件
- 一个用于
Post
的模型类,包含fillable
、casts
和dates
属性,以及关系方法。 - 一个创建
posts
表的迁移。 - 一个智能设置列的 factory。
- 一个用于
PostController
的控制器类,包含index
和store
动作,以及为每个 语句 生成的代码。 - 为
PostController
动作的路由。 - 一个基于
Post
模型定义进行验证的 form request,即StorePostRequest
。 - 一个包含通过构造函数设置的
post
属性的ReviewPost
可邮寄类。 - 一个包含通过构造函数设置的
post
属性的SyncMedia
作业类。 - 一个包含通过构造函数设置的
post
属性的NewPost
事件类。 - 由
PostController@index
渲染的post/index.blade.php
Blade 模板。
注意:此示例假设在默认 Laravel 应用程序中的功能,如 User
模型和 app.blade.php
布局。否则,生成的测试可能失败。
文档
浏览 Blueprint 文档,了解有关定义模型、定义控制器、高级配置和扩展 Blueprint 的完整详细信息。
支持策略
从版本2开始,Blueprint只为最新的稳定版Laravel(目前为Laravel 9)生成代码。如果您需要支持Laravel的旧版本,可以使用版本1或升级您的应用程序(《尝试使用Shift》)。
Blueprint仍然遵循语义化版本控制。然而,它是基于其语法的。任何对语法的更改都将增加其主版本号。否则,次要版本号的增加将包含新功能。这包括为Laravel的未来版本生成代码。