定制 mr.incognito/crudify 二次开发

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

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

mr.incognito/crudify

Composer 安装命令:

composer require mr.incognito/crudify

包简介

This package is for handling the crud for simple crud like for setup etc.

README 文档

README

A Laravel package to quickly scaffold API or Web-based CRUD operations using a simple Artisan command. It generates Models, Migrations, Form Requests, API Resources, Controllers, and even Blade views — with full support for validation, foreign keys, nullable fields, and default values.

Installation

To install the package, run:

composer require mr.incognito/crudify

✨ Features

  • ✅ Generates Model, Migration, Controller, Request, and Resource
  • ✅ Supports Web (with Blade views) or API type generation
  • ✅ Handles nullable fields (using ~ as a suffix)
  • ✅ Supports foreign key constraints
  • ✅ Adds default values to migration fields
  • ✅ Type-aware validation rules (e.g., string, integer, boolean)
  • ✅ Artisan-based generation: fast and developer-friendly
  • --type flag to specific crud type api or web based (with default is api)
  • --exclude flag to skip generating specific files
  • ✅ 🆕 delete:crud command to remove all generated files at once
  • ✅ Built-in Pest tests
  • ✅ Code refactoring via Rector

🚀 Usage

php artisan make:crud ModelName --fields="field:type|rule1|rule2;another:foreign~|constrained:table" --type=api|web --exclude=model,..

Example 1: Basic CRUD without foreign key

php artisan make:crud Department --fields="name:string|max:255;created_by:foreign~|constrained:users"

Example 2: Required foreign key with constraint and cascade

php artisan make:crud Department --fields="name:string;created_by:foreign|constrained:users|onDelete:cascade"

Example 3: Nullable foreign key column

php artisan make:crud Department --fields="name:string;created_by:foreign~|constrained:hospitals"

Example 4: Field with default value

php artisan make:crud Department --fields="name:string;status:boolean~|default:true"

These all will Generate

  • app/Models/Department.php
  • app/Http/Controllers/DepartmentController.php
  • app/Http/Requests/DepartmentRequest.php
  • app/Http/Resources/DepartmentResource.php
  • database/migrations/xxxx_xx_xx_create_departments_table.php
  • Adds route in routes/api.php

Example 5: Web CRUD with Blade Views

php artisan make:crud Article --fields="title:string;content:text" --type=web

Generates:

  • Model, Migration
  • Blade Views: resources/views/articles/*.blade.php
  • Web\ArticleController
  • Route in web.php

Example 6: Web CRUD excluding migration and model

php artisan make:crud Article --fields="title:string;content:text" --type=web --exclude=migration,model

Generates only:

  • Blade Views: resources/views/articles/*.blade.php
  • Web\ArticleController
  • Route in web.php

Example 7: Exclude Model and Migration (API)

php artisan make:crud Department --fields="name:string" --type=api --exclude=model,migration

Skips model and migration, still creates controller, request, and resource.

🗑️ Deleting Generated CRUD

Use delete:crud to remove all files generated by make:crud for a given resource in one command. It is the exact reverse of make:crud.

php artisan delete:crud ModelName --type=api|web --exclude=model,.. --force

Basic delete (defaults to API type)

php artisan delete:crud Hospital

Specify type

# Delete API CRUD files
php artisan delete:crud Hospital --type=api

# Delete Web CRUD files
php artisan delete:crud Hospital --type=web

Skip confirmation prompt

php artisan delete:crud Hospital --force

Exclude specific components from deletion

Keep certain files while deleting the rest — useful when you want to preserve your model or migration history.

# Keep the model
php artisan delete:crud Hospital --exclude=model

# Keep the migration (recommended to preserve DB history)
php artisan delete:crud Hospital --exclude=migration

# Keep both model and migration
php artisan delete:crud Hospital --exclude=model,migration

# Keep the route entry
php artisan delete:crud Hospital --exclude=route

# Keep controller and resource
php artisan delete:crud Hospital --exclude=controller,resource

Combine options

# Delete web CRUD, skip prompt, keep migration
php artisan delete:crud Hospital --type=web --exclude=migration --force

# Delete api CRUD, keep model and migration, no prompt
php artisan delete:crud Hospital --type=api --exclude=model,migration --force

What gets deleted

Component API path Web path
model app/Models/Hospital.php app/Models/Hospital.php
request app/Http/Requests/HospitalRequest.php app/Http/Requests/HospitalRequest.php
migration database/migrations/*_create_hospitals_table.php database/migrations/*_create_hospitals_table.php
controller app/Http/Controllers/Api/HospitalController.php app/Http/Controllers/Web/HospitalController.php
resource app/Http/Resources/HospitalResource.php
views resources/views/hospitals/ (entire directory)
route Strips entry from routes/api.php Strips entry from routes/web.php

Interactive confirmation

When run without --force, the command shows a preview and asks for confirmation before deleting anything:

The following files will be deleted for <Hospital> (api):
  ✗ [model]      app/Models/Hospital.php
  ✗ [request]    app/Http/Requests/HospitalRequest.php
  ✗ [migration]  database/migrations/2024_01_01_000000_create_hospitals_table.php
  ✗ [controller] app/Http/Controllers/Api/HospitalController.php
  ✗ [resource]   app/Http/Resources/HospitalResource.php

 Are you sure you want to delete these files? (yes/no) [no]:
 > yes

Deleted:
  ✓ [model]      app/Models/Hospital.php
  ✓ [request]    app/Http/Requests/HospitalRequest.php
  ✓ [migration]  database/migrations/2024_01_01_000000_create_hospitals_table.php
  ✓ [controller] app/Http/Controllers/Api/HospitalController.php
  ✓ [resource]   app/Http/Resources/HospitalResource.php
  ✓ [route]      removed route entry from routes/api.php

API CRUD for Hospital deleted successfully.

If a file was not found it is reported as skipped rather than throwing an error:

Not found (skipped):
  ? [migration]  database/migrations/*_create_hospitals_table.php

Field Syntax

Each field uses the format:

column_name:data_type[~]|rules|default:xyz;next_column:foreignId[~]|constrained:table

Supported Field Types

You can use any of the following Laravel migration column types:

string, text, boolean, integer, decimal, date, uuid, json, timestamp, etc.

  • Foreign key via foreign, e.g., user_id:foreign~|constrained:users
  • Nullable fields: suffix type with ~, e.g., email:string~
  • Default values: default:value, e.g., status:boolean|default:true

Column Modifiers

Modifier Description
~ Makes the field nullable
default:value Sets a default value in the migration
constrained Adds a foreign key constraint
onDelete:CASCADE Adds delete behavior for foreign keys

🆕 New in v2

🎯 --type=api — generates API controller and resource only

🎯 --type=web — generates web controller and Blade views

✂️ --exclude=model,migration,... — skip generating specific components

🗑️ delete:crud — reverse any make:crud with a single command

⚠️ Default Behavior

If --type is not specified, the command defaults to type=api.

php artisan make:crud Book --fields="title:string;author:string"

This is equivalent to:

php artisan make:crud Book --fields="title:string;author:string" --type=api

By default, it generates API-related files:

  • API Controller
  • API Resource
  • Form Request
  • Model
  • Migration
  • Adds route to api.php

Testing

This package uses Pest for testing:

composer test

Refactoring

This package uses Rector for automated code refactoring and PHP/Laravel upgrades:

composer rector

🛠 Dev Requirements

  • PHP ^8.1
  • Laravel ^10 or ^11 or ^12 or ^13
  • PestPHP for testing
  • Laravel Pint for code style

Contributing

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

Please make sure to update tests as appropriate.

🧑 Author

Sandeep Pant

📧 sandeeppant024@gmail.com

License

This package is open-sourced software licensed under the MIT License.

mr.incognito/crudify 适用场景与选型建议

mr.incognito/crudify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 288 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mr.incognito/crudify 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 288
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-10