usman / make-services
Comprehensive Laravel package for generating services, repositories, interfaces, actions, DTOs and more with artisan commands
Requires
- php: ^8.0
- illuminate/console: ^9.0|^10.0|^11.0
- illuminate/filesystem: ^9.0|^10.0|^11.0
- illuminate/support: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0|^8.0|^9.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
This package is not auto-updated.
Last update: 2025-09-24 19:54:58 UTC
README
A comprehensive Laravel package that provides artisan commands to quickly generate services, repositories, interfaces, actions, DTOs, traits, enums and more in your Laravel application.
✨ Features
- ✅ Service Classes - Generate service classes with optional CRUD methods
- ✅ Repository Pattern - Create repositories with model integration
- ✅ Interface Generation - Generate interfaces for dependency injection
- ✅ Action Classes - Single-purpose action classes (invokable or standard)
- ✅ Data Transfer Objects - DTOs with properties and array conversion
- ✅ Traits - Reusable trait classes
- ✅ Enums - Modern PHP 8.1+ enums with helper methods
- ✅ Service Stack - Generate complete stacks (Service + Repository + Interface + DTO)
- ✅ Nested Folders - Full support for nested directory structures
- ✅ Customizable - Configurable directories, namespaces, and templates
- ✅ Laravel 9, 10, 11 - Compatible with modern Laravel versions
- ✅ Professional UX - Emoji-based success/error messages with file paths
🚀 Installation
Install the package via composer:
composer require usman/make-services
Laravel Auto-Discovery
This package supports Laravel's auto-discovery feature, so the service provider will be automatically registered.
Publish Configuration (Optional)
php artisan make-services:publish-stubs
This will publish:
config/make-services.php
- Configuration fileresources/stubs/make-services/
- Customizable stub files
📚 Available Commands
🔧 Services
# Basic service php artisan make:services UserService # Service with CRUD methods php artisan make:services UserService --crud # Service with model integration php artisan make:services UserService --model=User --crud # Service with interface and repository php artisan make:services UserService --interface --repository
🏪 Repositories
# Basic repository php artisan make:repository UserRepository # Repository with model php artisan make:repository UserRepository --model=User # Repository with interface php artisan make:repository UserRepository --interface
🔌 Interfaces
# Basic interface php artisan make:interface UserServiceInterface # Interface with CRUD methods php artisan make:interface UserServiceInterface --crud # Create in Contracts directory php artisan make:interface UserContract --contract
⚡ Actions
# Standard action class php artisan make:action ProcessPayment # Invokable action class php artisan make:action ProcessPayment --invokable
📦 Data Transfer Objects (DTOs)
# Basic DTO php artisan make:dto UserData # DTO with properties php artisan make:dto UserData --properties="name:string,email:string,age:int" # Readonly DTO (PHP 8.2+) php artisan make:dto UserData --readonly --properties="name:string,email:string"
🧩 Traits
# Generate trait
php artisan make:trait Loggable
📋 Enums
# Basic integer enum php artisan make:enum Status # String enum with values php artisan make:enum Status --string --values="pending,approved,rejected"
🎯 Complete Service Stack
Generate everything at once:
# Complete stack for User php artisan make:service-stack User --model=User --crud # This creates: # - UserService (with CRUD methods) # - UserRepository (with User model) # - UserServiceInterface (with CRUD methods) # - UserRepositoryInterface (with CRUD methods) # - UserData (DTO)
📁 Generated File Structure
After using the commands, your project structure will look like:
app/
├── Services/
│ ├── UserService.php
│ └── Billing/
│ └── InvoiceService.php
├── Repositories/
│ ├── UserRepository.php
│ └── ProductRepository.php
├── Interfaces/
│ ├── UserServiceInterface.php
│ └── UserRepositoryInterface.php
├── Actions/
│ ├── ProcessPayment.php
│ └── SendNotification.php
├── DataTransferObjects/
│ ├── UserData.php
│ └── ProductData.php
├── Traits/
│ └── Loggable.php
└── Enums/
├── Status.php
└── UserRole.php
⚙️ Configuration
Customize the package by publishing the config file:
php artisan make-services:publish-stubs
Available Configurations
// config/make-services.php return [ 'directories' => [ 'services' => 'app/Services', 'repositories' => 'app/Repositories', 'interfaces' => 'app/Interfaces', 'actions' => 'app/Actions', 'dto' => 'app/DataTransferObjects', 'traits' => 'app/Traits', 'enums' => 'app/Enums', ], 'auto_generate' => [ 'service_interface' => false, 'repository_interface' => false, 'service_test' => false, ], 'templates' => [ 'include_crud_methods' => false, 'include_constructor' => true, 'include_docblocks' => true, ], ];
📖 Usage Examples
Service with Model Integration
php artisan make:services UserService --model=User --crud
Generates:
<?php namespace App\Services; use App\Models\User; use Illuminate\Database\Eloquent\Collection; class UserService { public function getAll(): Collection { return User::all(); } public function findById(int $id): ?User { return User::find($id); } public function create(array $data): User { return User::create($data); } // ... more CRUD methods }
DTO with Properties
php artisan make:dto UserData --properties="name:string,email:string,age:int"
Generates:
<?php namespace App\DataTransferObjects; class UserData { public function __construct( public string $name, public string $email, public int $age, ) { } public function toArray(): array { return [ 'name' => $this->name, 'email' => $this->email, 'age' => $this->age, ]; } public static function fromArray(array $data): static { return new static( $data['name'] ?? null, $data['email'] ?? null, $data['age'] ?? null, ); } }
String Enum with Values
php artisan make:enum UserRole --string --values="admin,editor,viewer"
Generates:
<?php namespace App\Enums; enum UserRole: string { case ADMIN = 'admin'; case EDITOR = 'editor'; case VIEWER = 'viewer'; public static function values(): array { return array_column(self::cases(), 'value'); } public static function options(): array { // Perfect for select inputs } }
🎯 Advanced Usage
Interface Binding
When using interfaces, don't forget to bind them in your AppServiceProvider
:
// In App\Providers\AppServiceProvider::register() $this->app->bind( \App\Interfaces\UserServiceInterface::class, \App\Services\UserService::class );
The make:service-stack
command will show you the exact binding code to use!
Custom Stub Files
After publishing stubs, you can customize templates in resources/stubs/make-services/
:
service.stub
- Service class templaterepository.stub
- Repository class templateinterface.stub
- Interface templateaction.stub
- Action class templatedto.stub
- DTO templatetrait.stub
- Trait templateenum.stub
- Enum template
🧪 Testing
composer test
📝 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.
💡 Why This Package?
Laravel doesn't include generators for service classes, repositories, interfaces, actions, DTOs, or modern enums. This package fills that gap with:
- Professional Templates - Well-structured, documented code
- Modern PHP - Supports latest PHP 8.x features
- Flexible Configuration - Customize everything to your needs
- Comprehensive Testing - Full test coverage
- Great Developer Experience - Clear messages, helpful output
Perfect for developers who follow clean architecture patterns, use the repository pattern, implement dependency injection with interfaces, or work with DTOs and modern PHP enums.
⭐ Support
If you find this package helpful, please consider giving it a ⭐ on GitHub!
For issues and feature requests, please use the GitHub issue tracker.