定制 brstreet2/laracrud 二次开发

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

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

brstreet2/laracrud

最新稳定版本:1.1.1

Composer 安装命令:

composer require brstreet2/laracrud

包简介

A Laravel package for generating API CRUD functionality

README 文档

README

LaraCRUD is a Laravel package designed to streamline the creation of API CRUD (Create, Read, Update, Delete) operations. It automates the generation of models, controllers, migrations, factories, routes, and more, enabling developers to focus on building features instead of repetitive boilerplate code.

Inspiration
This package was inspired by the efficient workflows and best practices advocated at my workplace. Special thanks to my engineering manager for the insightful guidance and the foundational idea behind LaraCRUD.

Features

  • Generates Eloquent models with optional migrations.
  • Creates API controllers with full CRUD functionality, including validation requests.
  • Sets up API routes automatically with customizable naming conventions.
  • Produces factories for model testing.
  • Generates feature tests for the API CRUD operations.
  • Supports interactive prompts for missing components.
  • Leverages customizable stubs for controllers, requests, and tests.

Installation

Install the package via Composer:

composer require brstreet2/laracrud --dev

If you prefer to install it globally:

composer global require brstreet2/laracrud

Usage

To generate CRUD operations for a specific model:

php artisan brstreet:api-crud {ModelName}

If the model does not exist, the command will prompt you to create it along with an optional migration.

Example

Generating CRUD for a Post model:

php artisan brstreet:api-crud Post

Files and Routes Created

  1. Model

    • File: app/Models/Post.php
    • If the model does not exist, the command will generate a new model.
  2. Controller

    • File: app/Http/Controllers/Api/PostController.php
    • A full-featured controller is created under the Api namespace.
  3. Migration

    • File: database/migrations/xxxx_xx_xx_create_posts_table.php
    • If no migration exists for the table, a new migration file is created.
  4. Factory

    • File: database/factories/PostFactory.php
    • A factory is created to support testing and seeding the model.
  5. Routes

    • Added in routes/api.php:
      Route::apiResource('posts', PostController::class)->names('posts');
    • The route path uses plural kebab case (posts), and route names are in plural snake case (posts.index, posts.store, etc.).
  6. Request Classes (generated if the controller is created)

    • Files:
      • app/Http/Requests/Post/IndexRequest.php
      • app/Http/Requests/Post/CreateRequest.php
      • app/Http/Requests/Post/UpdateRequest.php
    • These handle validation and permissions for API actions.
  7. Resource Class

    • File: app/Http/Resources/PostResource.php
    • Encapsulates the model data for API responses.
  8. Feature Test

    • File: tests/Feature/PostControllerTest.php
    • A test file is generated to validate the API's behavior.

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

This project is open-sourced software licensed under the MIT license.

Credits

  • Developed by brstreet2
  • Inspired by the engineering practices at my workplace, with special thanks to my engineering manager for the foundational idea.

统计信息

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

GitHub 信息

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

其他信息

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