joesu / laravel-scaffold
A powerful Laravel package that provides a complete implementation of Repository and Service patterns for rapid API development.
Requires
- php: ^8.1|^8.2|^8.3|^8.4
- laravel/framework: ^10.0|^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0
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
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
- π§ Issues: GitHub Issues
- π Documentation: GitHub Wiki
- π¬ Discussions: GitHub Discussions
β Show Your Support
If this package helps you, please give it a β on GitHub!
Built with β€οΈ for the Laravel community