myohanhtet / service-layer
A Laravel package to generate service layer files
v1.0.0
2025-05-01 16:17 UTC
Requires
- php: ^8.0
- illuminate/console: ^12.10
- illuminate/support: ^12.10
README
A SOLID-compliant service layer generator for Laravel applications that enforces best practices through interface-implementation separation.
✨ Features
- Automatic interface and implementation generation
- Auto-binding in Service Provider
- Proper namespace organization (
Services
andServices/Impl
) - Stub customization support
- SOLID architecture enforcement
- Laravel container integration
📦 Installation
Install via Composer:
composer require myohanhtet/service-layer
🚀 Usage
Basic Service Generation
php artisan make:service UserService
This creates:
app/
└── Services/
├── UserService.php # Interface
└── Impl/
└── UserServiceImpl.php # Implementation
🏗️ Generated Files
- Interface:
app/Services/UserService.php
<?php namespace App\Services; interface UserService { // Define your service contract here public function getAllUsers(); }
- Implementation:
app/Services/Impl/UserServiceImpl.php
<?php namespace App\Services\Impl; use App\Services\UserService; class UserServiceImpl implements UserService { public function getAllUsers() { // Your implementation here return User::all(); } }
- Auto-generated Binding in:
AppServiceProvider
:
$this->app->bind( \App\Services\UserService::class, \App\Services\Impl\UserServiceImpl::class );
🔧 Advanced Usage
Customizing Stubs
Publish the stubs to customize:
php artisan vendor:publish --provider="Myohanhtet\ServiceLayer\ServiceLayerServiceProvider" --tag=stubs
Then modify:
stubs/service.stub
stubs/service-impl.stub
Manual Binding:
if auto-binding fails, you can manually bind the service in your AppServiceProvider
:
$this->app->bind( \App\Services\UserService::class, \App\Services\Impl\UserServiceImpl::class );
🛠️ Requirements
- PHP 8.0 or higher
- Laravel 11 or higher
🤝 Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss.
- Fork the repository
- Create your feature branch (
git checkout -b feature/YourFeature
) - Commit your changes (
git commit -m 'Add some feature'
) - Push to the branch (
git push origin feature/YourFeature
) - Open a pull request
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ by Myo Han Htet