joesu/laravel-scaffold

A powerful Laravel package that provides a complete implementation of Repository and Service patterns for rapid API development.

v1.1.0 2025-06-27 16:20 UTC

This package is auto-updated.

Last update: 2025-06-27 16:33:26 UTC


README

From 0 to Complete API in 30 Seconds - Auto-generate Repository, Service, Controller, Tests, and Smart Cleanup

PHP Version Laravel Version License Tests

Solve the Problem: Eliminate repetitive CRUD code, improve test coverage, and manage generated files intelligently in Laravel development.

🎯 Why Choose Laravel Scaffold?

Feature Laravel Scaffold Other Packages
Auto-Generated Tests βœ… Complete test coverage ❌ Manual test writing
Smart Cleanup βœ… One-click cleanup ❌ Manual file deletion
Multilingual Support βœ… Built-in EN/CN ❌ English only
Batch Operations βœ… Full support ❌ Partial support
Relationship Filtering βœ… Advanced queries ❌ Basic only
Soft Delete Support βœ… Complete implementation ❌ Limited support

πŸš€ Quick Start

# Install the package
composer require joesu/laravel-scaffold

# Generate complete CRUD architecture
php artisan make:repository User

# Run tests (auto-generated!)
php artisan test --filter=UserTest

30 seconds later, you have a complete User API with full test coverage!

🎯 Perfect For

  • βœ… Enterprise API Development - Production-ready architecture
  • βœ… SaaS Backend Systems - Scalable service layer
  • βœ… Rapid Prototyping - Quick MVP development
  • βœ… Team Collaboration - Consistent code patterns
  • βœ… Code Quality - Built-in testing and error handling

πŸ—οΈ Architecture

Laravel Scaffold provides a complete layered architecture with enterprise-grade patterns:

Base Interfaces

  • BaseRepositoryInterface: Complete repository contract
  • BaseServiceInterface: Service layer contract

Base Classes

  • BaseRepository: Full CRUD implementation with advanced features
  • BaseService: Business logic layer with batch operations

Generated Structure

When you run php artisan make:repository User, you get:

app/
β”œβ”€β”€ Models/
β”‚   └── User.php                    # Eloquent Model
β”œβ”€β”€ Http/
β”‚   β”œβ”€β”€ Controllers/
β”‚   β”‚   └── UserController.php      # API Controller
β”‚   └── Requests/
β”‚       β”œβ”€β”€ StoreUserRequest.php    # Validation rules
β”‚       └── UpdateUserRequest.php   # Update validation
β”œβ”€β”€ Repositories/
β”‚   └── UserRepository.php          # Extends BaseRepository
β”œβ”€β”€ Services/
β”‚   └── UserService.php             # Extends BaseService
β”œβ”€β”€ Tests/
β”‚   β”œβ”€β”€ Feature/
β”‚   β”‚   └── UserTest.php            # Auto-generated tests
β”‚   └── Unit/
β”‚       β”œβ”€β”€ UserRepositoryTest.php  # Repository tests
β”‚       └── UserServiceTest.php     # Service tests
└── Contracts/
    β”œβ”€β”€ UserRepositoryInterface.php # Repository contract
    └── UserServiceInterface.php    # Service contract

✨ Key Features

πŸ§ͺ Auto-Generated Tests (Unique Feature!)

# Automatically generates comprehensive tests
php artisan make:repository User

# Run the generated tests
php artisan test --filter=UserTest

Generated test coverage includes:

  • βœ… CRUD operations testing
  • βœ… Validation rules testing
  • βœ… Error handling testing
  • βœ… Batch operations testing
  • βœ… Soft delete testing

🧹 Smart Cleanup System

# Clean up generated files when needed
php artisan scaffold:cleanup User

# Clean with confirmation
php artisan scaffold:cleanup User --confirm

# Clean with backup
php artisan scaffold:cleanup User --backup

Safely removes:

  • Generated controllers, repositories, services
  • Test files
  • Request validation classes
  • Interface contracts
  • API routes (optional)

πŸ”„ Advanced Repository Features

  • Complete CRUD operations with error handling
  • Advanced query methods with relationship loading
  • Smart filtering system (JSON and array formats)
  • Relationship field filtering (e.g., 'user.name')
  • Configurable sorting with whitelist protection
  • Batch operations (create, update, delete)
  • Soft delete support with restore functionality
  • Multilingual error messages (EN/CN)

πŸŽ›οΈ Service Layer Features

  • Business logic encapsulation
  • Batch operations with transaction support
  • Utility methods (updateOrCreate, exists, count)
  • Soft delete operations
  • Error handling with custom exceptions

πŸ“‘ API Usage Examples

Basic Operations

# Get all users with pagination
GET /api/users?per_page=10&page=1

# Sort by creation date
GET /api/users?order_by=created_at&order_direction=desc

# Load relationships
GET /api/users?with[]=posts&with[]=profile

# Relationship counts
GET /api/users?with[]=posts.count&with[]=comments.count

Advanced Filtering

# Simple filtering
GET /api/users?filters[0][]=email&filters[0][]=user@example.com

# Complex filtering
GET /api/users?filters[0][]=created_at&filters[0][]=>=&filters[0][]=2024-01-01

# JSON format filtering
GET /api/users?filters[0]={"field":"status","operator":"=","value":"active"}

# Filter by related table columns
GET /api/users?filters[0][]=posts.title&filters[0][]=Laravel&filters[0][]=LIKE

Batch Operations

# Batch create
POST /api/users/batch-store
{
    "users": [
        {"name": "John", "email": "john@example.com"},
        {"name": "Jane", "email": "jane@example.com"}
    ]
}

# Batch update
PUT /api/users/batch-update
{
    "ids": [1, 2, 3],
    "attributes": {"status": "active"}
}

# Batch delete
DELETE /api/users/batch-destroy
{
    "ids": [1, 2, 3]
}

πŸ› οΈ Installation & Setup

1. Install Package

composer require joesu/laravel-scaffold

2. Publish Configuration (Optional)

php artisan vendor:publish --provider="JoeSu\LaravelScaffold\Providers\LaravelScaffoldServiceProvider"

3. Generate Your First CRUD

# Complete CRUD generation
php artisan make:repository User

# Selective generation
php artisan make:repository User --repository --service
php artisan make:repository User --model --migration
php artisan make:repository User --request

🌍 Multilingual Support

Built-in support for multiple languages with automatic error message translation:

Supported Languages

  • πŸ‡ΊπŸ‡Έ English (en)
  • πŸ‡ΉπŸ‡Ό Chinese Traditional (zh-TW)

Publishing Language Files

# Publish all language files
php artisan vendor:publish --provider="JoeSu\LaravelScaffold\Providers\LaravelScaffoldServiceProvider" --tag=lang

Error Message Examples

// English
"Record with ID 123 not found"
"Failed to create model: SQLSTATE[23000]: Integrity constraint violation"

// Chinese Traditional (when locale is zh-TW)
"ζ‰ΎδΈεˆ° ID η‚Ί 123 ηš„θ¨˜ιŒ„"
"ε»Ίη«‹ζ¨‘εž‹ε€±ζ•—: SQLSTATE[23000]: Integrity constraint violation"

πŸ”§ Configuration

The package automatically registers service providers and bindings. For custom configuration:

# Publish config file
php artisan vendor:publish --provider="JoeSu\LaravelScaffold\Providers\LaravelScaffoldServiceProvider"

πŸ§ͺ Testing

# Run package tests
composer test

# Run with coverage
composer test-coverage

πŸ“‹ Requirements

  • PHP: ^8.1|^8.2|^8.3|^8.4
  • Laravel: ^10.0|^11.0|^12.0

πŸ”„ Version Compatibility

Laravel Version PHP Version Status
10.x ^8.1 βœ… Supported
11.x ^8.2 βœ… Supported
12.x ^8.2 βœ… Supported

For detailed version compatibility, see VERSION_COMPATIBILITY.md.

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

πŸ“„ License

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

πŸ†˜ Support

⭐ Show Your Support

If this package helps you, please give it a ⭐ on GitHub!

Built with ❀️ for the Laravel community