第三方扩展包--Blueprint
2022-12-27 本文已影响0人
hankin_h
Blueprint 通过配置文件快速完成 Laravel 数据库迁移、模型类、工厂类等组件的编排和创建:
- 安装扩展
$ composer require --dev laravel-shift/blueprint
$ php artisan blueprint:new --config
- 然后在 draft.yaml 中编写模型
models:
Department:
uuid: uuid
name: string:50
description: longtext
relationships:
hasMany: Employee
Employee:
uuid: uuid
full_name: string:100
email: string:100 index
department_id: id foreign
job_title: string:50
payment_type: string:20
salary: integer unsigned nullable
hourly_rate: integer unsigned nullable
- 运行如下命令即可生成对应的模型类、数据库迁移以及模型工厂:
$ php artisan blueprint:build
Created:
- database/factories/DepartmentFactory.php
- database/factories/EmployeeFactory.php
- database/migrations/2022_12_28_075857_create_departments_table.php
- database/migrations/2022_12_28_075858_create_employees_table.php
- app/Models/Department.php
- app/Models/Employee.php
- 最后运行数据库迁移
$ php artisan migrate