承接 jcsoriano/laravel-crud-templates 相关项目开发

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

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

jcsoriano/laravel-crud-templates

Composer 安装命令:

composer require jcsoriano/laravel-crud-templates

包简介

Laravel CRUD Templates - Generate complete CRUD operations with a single command

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status

CRUD Templates for Laravel allows you to generate controllers, models, policies, requests, resources, migrations, factories, and even tests - all the files you need to complete CRUD features with a single command.

You can completely modify the template or create your own templates to fit your project's conventions perfectly.

Demo

Requirements

  • PHP 8.4 or higher
  • Laravel 11.0 or 12.0

Installation

You can install the package via Composer as a dev dependency:

composer require --dev jcsoriano/laravel-crud-templates

The package will automatically register itself via Laravel's package discovery.

Publishing Stubs (Optional)

You can publish the stubs to customize them:

php artisan vendor:publish --tag="crud-templates-stubs"

The Command

To generate a CRUD feature, you may use this command:

php artisan crud:generate
  {model : The name of the model}
  {--fields= : The fields to generate. Format: field1:type1,field2?:type2}
  {--table= : The database table to generate the fields from}
  {--template=api : The CRUD template to generate}
  {--skip= : List of files you want to skip}
  {--options= : Other options to pass to the generator. Format: key1:value1,key2:value2}
  {--force : Overwrite existing files}

Quick Start Example

Sample command to generate a fully functioning RESTful API:

php artisan crud:generate Content/Post --template=api --fields="title:string,content:text,published_at:datetime,category:belongsTo,comments:hasMany,status:enum:PublishStatus" --options="scope:user"

Generated Files

This command generates all the files needed to complete the CRUD feature, from routes, to validation, to authorization, to API responses, to migrations, to factories, to tests, and more.

  • app/Http/Controllers/Api/Content/PostController.php
  • app/Models/Content/Post.php
  • app/Policies/PostPolicy.php
  • app/Http/Requests/Content/StorePostRequest.php
  • app/Http/Requests/Content/UpdatePostRequest.php
  • app/Http/Resources/Content/PostResource.php
  • database/migrations/{timestamp}_create_posts_table.php
  • database/migrations/{timestamp}_create_{pivot}_tables.php (if belongsToMany or morphToMany relationships are present)
  • database/factories/Content/PostFactory.php
  • tests/Feature/Api/Content/PostControllerTest.php
  • API routes automatically added to routes/api.php (will run install:api if the file doesn't exist yet)
  • Laravel Pint run on all generated files

Generated Routes

The command automatically registers the following routes in your routes/api.php file:

HTTP Method URI Action Description
GET /api/posts index List all posts (paginated)
POST /api/posts store Create a new post
GET /api/posts/{id} show Show a specific post
PUT/PATCH /api/posts/{id} update Update a post
DELETE /api/posts/{id} destroy Delete a post

Response Format

Single Resource:

{
  "data": {
    "id": 1,
    "title": "My Post",
    "content": "...",
    "category": { "...": "..." },
    "comments": [ { "...": "..." } ],
    "status": "published",
    "published_at": "2024-01-01T00:00:00.000000Z",
    "created_at": "2024-01-01T00:00:00.000000Z",
    "updated_at": "2024-01-01T00:00:00.000000Z"
  }
}

Collection (with pagination):

{
  "data": [
    { "The Post object as above" },
  ],
  "links": { "first": "...", "last": "...", "prev": null, "next": "..." },
  "meta": { "current_page": 1, "per_page": 15, "total": 50 }
}

Validation Rules

The request classes automatically include appropriate validation:

StorePostRequest:

public function rules(): array
{
    return [
        'title' => ['required', 'string', 'max:255'],
        'content' => ['required', 'string'],
        'published_at' => ['required', 'date'],
        'category_id' => ['bail', 'required', 'exists:categories,id'],
        'status' => ['required', Rule::enum(PublishStatus::class)],
    ];
}

Model Enhancements

The generated Post model will include several automatic enhancements:

Relationship Methods:

public function category(): BelongsTo
{
    return $this->belongsTo(Category::class);
}

public function comments(): HasMany
{
    return $this->hasMany(Comment::class);
}

Type Casting:

protected $casts = [
    'published_at' => 'immutable_datetime',  // Automatic datetime casting
    'status' => PublishStatus::class,        // Enum casting
];

Fillable Fields:

protected $fillable = [
    'title',
    'content',
    'published_at',
    'category_id',
    'status',
];

Migration with Foreign Keys

The migration includes proper foreign key constraints:

Schema::create('posts', function (Blueprint $table) {
    $table->id();
    $table->string('title');
    $table->text('content');
    $table->dateTime('published_at');
    $table->foreignId('category_id')->constrained();
    $table->string('status');
    $table->timestamps();
});

API Resource

The generated PostResource automatically includes relationships:

public function toArray($request): array
{
    return [
        ...
        'category' => CategoryResource::make($this->whenLoaded('category')),
        'comments' => CommentResource::collection($this->whenLoaded('comments')),
    ];
}

Documentation

📚 View Full Documentation

Getting Started

Available Templates

Using Templates

Customizing Templates

Support

If you find this package useful and would like to support its development, consider supporting me through one of these platforms:

Buy Me a Coffee Patreon Ko-fi

Your support helps me continue building and maintaining this package. Thank you! 🙏

Coming Soon

  1. Filament CRUD Generator - a Filament GUI for generating CRUD features
  2. Livewire CRUD Generator - a CRUD template built for the Livewire starter kit
  3. Vue CRUD Generator - a CRUD template built for the Vue starter kit
  4. React CRUD Generator - a CRUD template built for the React starter kit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

jcsoriano/laravel-crud-templates 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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