定制 codebider/generate-crud 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

codebider/generate-crud

Composer 安装命令:

composer require codebider/generate-crud

包简介

An artisan command to automate the migration,model,resource controller, views and routes

README 文档

README

Laravel Crud Generator

Packagist Downloads Packagist Version

This Laravel CRUD Generator package provides and generates Controller, Model (with eloquent relations), Migration, Routes and Views for developing your applications with a single command.

Features

  1. Automatically generates files in the proper directory structure:

    • Migration
    • Model
    • Controller
    • Views
    • Routes
  2. Interactive prompts for input:

    • Asks for the model name (e.g., Product, User).
    • Collects field names, their data types, and whether they are nullable or not.
    • Allows you to add relationships in the model.
  3. Provides options for:

    • Previewing the generated migration file before saving.
    • Editing the migration file directly in the system's editor specified in the configuration file.
  4. Automatically propagates updates:

    • If you edit fields in the migration file, these changes will also be applied to dependent components like the $fillable property in models.
  5. Controller creation:

    • Choose between generating a basic controller or a resource controller.
  6. Route creation:

    • Choose to generate routes in either web.php or api.php.
  7. View file generation:

    • Choose to generate blade file or not.

Requirements

Laravel >= 8.x
PHP >= 7.4

Installation

1 - Install

composer require codebider/generate-crud

2- Publish the default package's config

php artisan vendor:publish --tag=crud-generator-config

Usage with Workflow

This tool can create the files by typing the command

    php artisan generate:crud
  1. Model Name:

    • Enter the desired model name (e.g., Product, Category). Follow Laravel's naming conventions (singular and CamelCase).
          Enter the model name:
      
  2. Field Names and Types:

    • Input field names along with their data types and whether they are nullable. Use the following format:
         Enter field name (or press enter to stop adding fields):
      
      Example:
         Enter field name (or press enter to stop adding fields):
         > name
         Select field type by default (string):
         [0 ] string    
         [1 ] text      
         [2 ] longText  
         [3 ] integer   
         [4 ] unsignedIn
         [5 ] bigInteger
         [6 ] unsignedBi
         [7 ] json      
         [8 ] jsonb     
         [9 ] enum      
         [10] decimal   
         [11] float     
         [12] ipAddress 
         [13] boolean   
         [14] date      
         [15] datetime  
         [16] timestamp 
         > 0
         Nullable  [Yes]:
         [0] Yes
         [1] No
         > 0
      
    • Press Enter without typing anything to end the field input process.
          Enter field name (or press enter to stop adding fields):
          >
          Creating Migration File
          Updating Migration File
          fields are : name
      
  3. Preview Migration File:

    • Once all fields are entered, preview the migration file to verify its contents.
          Do you want to review the migration file before proceeding? (yes/no) [yes]:
          > yes
          Opening migration file: G:\laragon\www\Expense\database\migrations/Api/2024_12_29_105049_create_products_table.php
      
  4. Edit Migration File:

    • Preview migration in the specified operating system in the config file e.g(config/crud_generator.php).
  5. Propagating Changes:

    • Any changes made to the migration file will automatically update other components where fields are required (e.g., $fillable in models).
          Is the migration file correct? (yes/no) [yes]:
          > yes
          Migration file is correct.
          Migrated Successfully.
          Creating Model
      
  6. Adding Relationships:

    • Add relationships (e.g., one-to-one, one-to-many, many-to-many) to the model by following the interactive prompts.
          Do you want to add relationships to this model? [No]:
          [0] Yes
          [1] No
          > 0
      
  7. Creating a Controller:

    • Choose to create a controller
          Do you want to generate Controller? [Yes]:
          [0] Yes
          [1] No
          >
      
    • Choose between a basic controller (minimal functionality) or a resource controller (includes all RESTful methods).
          Do you want to create a resource controller or a basic controller? [resource]:
          [0] resource
          [1] basic
          >
      
    • After Selection
          Resource controller created successfully at G:\laragon\www\Expense\app\Http\Controllers\Api\ProductController.php
      
  8. Generating Routes:

    • Select whether the routes should be added to web.php or api.php based on your application requirements.
          Where do you want to add routes? [web.php]:
          [0] api.php
          [1] web.php
          >
      
    • After Selection
          Generating web routes...
          Added route to G:\laragon\www\Expense\routes/web.php
      
  9. Creating View Files:

    • Choose to create a view file
          Do you want to generate views? [Yes]:
          [0] Yes
          [1] No
          >
      
    • After Selection
          Generating views...
          Created view file: G:\laragon\www\Expense\resources\views\Api\products/index.blade.php
      
  10. Successfully created the crud

    • After completion of all the steps, you will see a success message indicating that the CRUD operation
          Migration and cache cleared successfully!
          CRUD files for Product generated successfully!
          Log sent to server successfully.
      

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Author

Awais Javaid Email Me

Hire Me LinkedIn

codebider/generate-crud 适用场景与选型建议

codebider/generate-crud 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138 次下载、GitHub Stars 达 13, 最近一次更新时间为 2025 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「crud」 「laravel」 「crud generator」 「laravel package」 「laravel crud generator」 「crud bot」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 codebider/generate-crud 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 codebider/generate-crud 我们能提供哪些服务?
定制开发 / 二次开发

基于 codebider/generate-crud 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 138
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 13
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-11