dev-lnk/laravel-code-builder 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dev-lnk/laravel-code-builder

最新稳定版本:v1.2

Composer 安装命令:

composer require dev-lnk/laravel-code-builder

包简介

Generate classes and files from table schema

README 文档

README

Latest Stable Version Total Downloads tests License
Laravel required PHP required

Description

Hello Laravel users! This package allows you to generate code from the schema of your SQL table. The following entities will be generated:

These examples have been generated from a table created by migration:

Schema::create('products', function (Blueprint $table) {
    $table->id();
    $table->string('title')->default('Default');
    $table->text('content');
    $table->foreignIdFor(User::class)
        ->nullable()
        ->constrained()
        ->nullOnDelete()
        ->cascadeOnUpdate();
    $table->smallInteger('sort_number')->default(0);
    $table->boolean('is_active')->default(0);
    $table->timestamps();
    $table->softDeletes();
});

What is this package for?

This package allows you to significantly reduce the routine while coding and focus on developing.

Installation

composer require dev-lnk/laravel-code-builder --dev

Configuration:

Publish the package configuration file:

php artisan vendor:publish --tag=laravel-code-builder

Usage

The basic command signature looks like this:

code:build {entity} {table?}

Let's say we want to create classes for the base table users based on the User entity. To do this you need to run the following command:

php artisan code:build User

You will be presented with a list of your tables, choose which table you want to generate the code based on:

 ┌ Table ───────────────────────────────────────────────────────┐
 │   ○ migrations                                             │ │
 │   ○ password_reset_tokens                                  │ │
 │   ○ products                                               │ │
 │   ○ sessions                                               │ │
 │ › ● users                                                  ┃ │
 └──────────────────────────────────────────────────────────────┘

You can also specify part of the table name to shorten the list

php artisan code:build User us
 ┌ Table ───────────────────────────────────────────────────────┐
 │ › ● users                                                    │
 └──────────────────────────────────────────────────────────────┘

If you have not specified a generation_path in the configuration file, you will be offered 2 options:

 ┌ Where to generate the result? ───────────────────────────────┐
 │ › ● In the project directories                               │
 │   ○ To the generation folder: `app/Generation`               │
 └──────────────────────────────────────────────────────────────┘

The first option will create all files according to the folders in your app_path directory. If a file with the same name is found, you will be prompted to replace it:

app/Models/User.php was created successfully!
...
 ┌ Controller already exists, are you sure you want to replace it? ┐
 │ Yes                                                             │
 └─────────────────────────────────────────────────────────────────┘

app/Http/Controllers/UserController.php was created successfully!
...

In the second option, all files will be generated in the app/Generation folder

app/Generation/Models/User.php was created successfully!
...

In the builders configuration you can comment out those builders that you do not want to be executed

return [
    'builders' => [
        'model',
//        'addAction',
//        'editAction',
//        'request',
//        'controller',
//        'route',
        'form',
//        'DTO',
//        'table',
    ],
    //...
];

You can generate certain entities using flags:

php artisan code:build user --model --request

Available options for the only flag:

  • --model
  • --request
  • --DTO
  • --addAction
  • --editAction
  • --controller
  • --route
  • --form
  • --table
  • --typeScript
  • --builder - Generates all builders specified in the builders configuration + your specified flag, for example:
php artisan code:build user --builders --request

Documentation

统计信息

  • 总下载量: 4.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固