mosweed/laravel-auto-crud 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mosweed/laravel-auto-crud

最新稳定版本:v1.0.3

Composer 安装命令:

composer require mosweed/laravel-auto-crud

包简介

Complete CRUD scaffolding generator for Laravel 12 with API, Blade views, Livewire components, automatic routing, custom layouts, and more

README 文档

README

Laravel Auto CRUD

Laravel Auto CRUD

Generate complete CRUD scaffolding in seconds

Website

Tests Latest Version Downloads License Stars

InstallationQuick StartFeaturesDocumentation

⚡ Features

Feature Description
🏗️ Complete CRUD Models, Controllers, Views, Routes in one command
🌐 API & Web Generate API and Web controllers simultaneously
🎨 Modern Views Tailwind v4 & Bootstrap 5 with dark mode
Livewire Real-time table and form components
🛣️ Auto Routing Routes automatically added to your files
🏠 App Layout Ready-to-use layout with navigation
🎯 Tailwind v4 Auto-detects and configures CSS variables
🗑️ Soft Deletes Full restore/force-delete support
🔍 Filter & Sort Built-in query traits
🧪 Tests Automatic Pest/PHPUnit generation
📋 JSON Config Batch generate multiple CRUDs
↩️ Rollback Auto cleanup on errors

📋 Requirements

  • PHP 8.2+
  • Laravel 11.x or 12.x

📦 Installation

composer require mosweed/laravel-auto-crud

Publish Layout & Welcome Page

php artisan crud:layout --welcome

Publish Configuration (Optional)

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

🚀 Quick Start

# 1. Publish layout and welcome page
php artisan crud:layout --welcome

# 2. Generate a complete CRUD
php artisan make:crud Product \
    --fields="name:string,price:decimal,description:text:nullable" \
    --belongsTo=Category \
    --all \
    --add-to-nav

# 3. Run migrations
php artisan migrate

# 4. Build assets
npm run build

Your CRUD is ready at /products

💻 Usage

Basic Command

php artisan make:crud Post

This generates:

  • ✅ Model with Filterable and Sortable traits
  • ✅ Web Controller
  • ✅ API Controller
  • ✅ Form Requests (Store & Update)
  • ✅ Policy
  • ✅ Blade Views (index, create, edit, show)
  • ✅ Routes in web.php and api.php

Command Options

Option Description
--type=api|web|both Output type (default: both)
--css=tailwind|bootstrap CSS framework (default: tailwind)
--all Generate migration, factory, seeder, and tests
--force Overwrite existing files
--soft-deletes Add soft delete support
--livewire Generate Livewire components
--tests Generate feature and unit tests
--fields=... Define fields inline
--belongsTo=Model Add belongsTo relationship
--hasMany=Model Add hasMany relationship
--belongsToMany=Model Add belongsToMany relationship
--json=path Generate from JSON configuration
--add-to-nav Add to navigation menu

Defining Fields

php artisan make:crud Post --fields="title:string,body:text,is_published:boolean"

Supported Types

Type Database Column
string VARCHAR
text TEXT
integer INTEGER
boolean BOOLEAN
date DATE
datetime DATETIME
decimal DECIMAL
json JSON
foreignId BIGINT UNSIGNED

Modifiers

--fields="title:string:255,slug:string:unique,body:text:nullable"
  • nullable - Field can be null
  • unique - Add unique constraint
  • 255 - String length

Relationships

# BelongsTo
php artisan make:crud Post --belongsTo=User --belongsTo=Category

# HasMany
php artisan make:crud User --hasMany=Post

# BelongsToMany
php artisan make:crud Post --belongsToMany=Tag

JSON Configuration

Create a crud.json file:

{
    "models": [
        {
            "name": "Product",
            "fields": [
                {"name": "name", "type": "string"},
                {"name": "price", "type": "decimal"}
            ],
            "relationships": [
                {"type": "belongsTo", "model": "Category"}
            ]
        }
    ],
    "options": {
        "all": true,
        "softDeletes": true
    }
}

Run:

php artisan make:crud --json=crud.json

🏠 Layout Command

php artisan crud:layout
Option Description
--css=bootstrap Use Bootstrap instead of Tailwind
--force Overwrite existing layout
--welcome Also publish welcome/dashboard page
--models=Product Pre-populate navigation

Welcome Page

# Layout + welcome page together
php artisan crud:layout --welcome

# With Bootstrap
php artisan crud:layout --css=bootstrap --welcome

🔍 Filtering & Sorting

The generated models include Filterable and Sortable traits:

// Filter
GET /products?status=active
GET /products?price_from=10&price_to=100
GET /products?search=keyword

// Sort
GET /products?sort=name&direction=asc

// Soft Deletes
GET /products?trashed=1

🎨 Tailwind v4 Colors

Laravel 12 uses Tailwind v4 by default. Edit resources/css/app.css:

@theme {
    /* Primary - Change to green */
    --color-primary-500: #22c55e;
    --color-primary-600: #16a34a;
    --color-primary-700: #15803d;

    /* Secondary */
    --color-secondary-500: #6366f1;
    --color-secondary-600: #4f46e5;
}

📁 Generated Files

app/
├── Http/Controllers/
│   ├── ProductController.php
│   └── Api/ProductController.php
├── Http/Requests/Product/
│   ├── StoreProductRequest.php
│   └── UpdateProductRequest.php
├── Models/Product.php
└── Policies/ProductPolicy.php

database/
├── factories/ProductFactory.php
├── migrations/xxxx_create_products_table.php
└── seeders/ProductSeeder.php

resources/views/
├── components/app-layout.blade.php
├── welcome.blade.php
└── products/
    ├── index.blade.php
    ├── create.blade.php
    ├── edit.blade.php
    └── show.blade.php

📖 Documentation

For complete documentation, see DOCUMENTATION.md.

🧪 Testing

composer test

📝 Changelog

See CHANGELOG.md for recent changes.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🔒 Security

If you discover any security-related issues, please open an issue on GitHub.

👨‍💻 Credits

📄 License

The MIT License (MIT). See LICENSE for more information.

⬆ Back to Top

Made with ⚡ by Mosweed

统计信息

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

GitHub 信息

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

其他信息

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