承接 mohammedhassan/crud-package 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mohammedhassan/crud-package

Composer 安装命令:

composer require mohammedhassan/crud-package

包简介

A Laravel package to generate CRUD scaffolds.

README 文档

README

This package provides an Artisan command make:crud to quickly scaffold a complete CRUD (Create, Read, Update, Delete) module for your Laravel application. It generates a Model, Migration, Controller, Service, DTOs, and an API Resource, following a structured and scalable pattern.

Features

  • Generates a full CRUD setup with a single command.
  • Uses Data Transfer Objects (DTOs) for validation and data handling.
  • Creates a dedicated Service layer for business logic.
  • Automatically updates the migration file based on a schema definition.
  • Adds API resource routes automatically.
  • Highly customizable through options.

Installation

You can install the package via composer:

composer require mohammedhassan/crud-package

The package will automatically register its service provider. The necessary dependency wendelladriel/laravel-validated-dto will be installed automatically.

Usage

To generate a new CRUD module, use the following Artisan command:

php artisan make:crud {name} {--schema=} {--api-route=} {--controller-route=}

Arguments

  • {name}: The name of the resource (e.g., Product). This will be used to generate the class names.

Options

  • --schema=<path>: (Optional) The path to a schema file. The schema file defines the validation rules and database columns for the model.
  • --api-route=<path>: (Optional) The path to the API routes file where the resource route will be added. Defaults to routes/api.php.
  • --controller-route=<path>: (Optional) A sub-path for the controller's namespace and directory. For example, V1/Admin will place the controller in App/Http/Controllers/V1/Admin.

Basic Example

This command will generate the CRUD files for a "Product" resource.

php artisan make:crud Product

Advanced Example with Schema

This command will generate the CRUD files for a "Post" resource, using a schema definition for validation and migration fields.

php artisan make:crud Post --schema=app/Schemas/PostSchema.php

What It Generates

The make:crud command creates the following files and components:

  1. Model: app/Models/{Name}.php

    • Includes standard Eloquent setup.
    • Adds helper methods for CRUD operations (store{Name}, update{Name}, etc.).
  2. Migration: database/migrations/..._create_{name_plural}_table.php

    • Creates the database table for the model.
    • If a --schema is provided, it automatically adds the columns to the migration file.
  3. Controller: app/Http/Controllers/{Name}Controller.php

    • A standard RESTful controller with index, store, update, and destroy methods.
    • Uses the generated Service and DTOs for handling requests.
  4. Service: app/Services/{Name}Service.php

    • Contains the business logic for the CRUD operations, keeping the controller thin.
  5. DTOs (Data Transfer Objects): app/DTOs/Service/{Name}/

    • Store{Name}DTO.php: For validating store requests.
    • Update{Name}DTO.php: For validating update requests.
    • Delete{Name}DTO.php: For validating delete requests.
    • List{Name}DTO.php: For handling listing/pagination parameters.
  6. API Resource: app/Http/Resources/{Name}Resource.php

    • For transforming the model into a JSON response.
  7. Route:

    • Appends an apiResource route to your API routes file (e.g., routes/api.php).
  8. Response Helper: app/Helpers/ResponsesHelper.php

    • A helper class for generating standardized JSON API responses. This is only created if it doesn't already exist.

The Schema File

The schema file allows you to define the fields for your model. It should be a PHP file that returns an array where keys are the field names and values are their Laravel validation rules. The command uses these rules to generate DTOs and migration columns.

Example Schema: app/Schemas/PostSchema.php

<?php

// app/Schemas/PostSchema.php

return [
    'Post' => [
        'title' => 'required|string|max:255',
        'body' => 'required|string',
        'is_published' => 'sometimes|boolean',
        'user_id' => 'required|integer|exists:users,id',
    ],
    // You can define other model schemas here
];

The command will look for the key that matches the model name (e.g., Post).

Customization

  • Controller Location: Use the --controller-route option to organize controllers into subdirectories. For example, --controller-route=Api/V1 will create the controller at app/Http/Controllers/Api/V1/{Name}Controller.php.
  • Route File: Use the --api-route option to specify a different file for adding the API routes, like routes/admin.php.
  • Generated Code: After running the command, you are free to modify any of the generated files to fit your specific needs.

Author

This CRUD generator was created by Mohammed Hassan.

mohammedhassan/crud-package 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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