mitul456 / laravel-repository-service
A Laravel package to generate repository and service layers using artisan commands
Package info
github.com/mitul456/laravel-repository-service
pkg:composer/mitul456/laravel-repository-service
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
README
A powerful Laravel package to automatically generate Repository and Service layers, helping you build clean, maintainable, and testable applications.
🇧🇩 বাংলা: এটি একটি Laravel প্যাকেজ যা Repository Pattern এবং Service Layer স্বয়ংক্রিয়ভাবে তৈরি করে, আপনার কোডকে আরও ক্লিন এবং মেইন্টেইনেবল করে তোলে।
⚡ Quick Start
Install the package via Composer:
composer require mitul456/laravel-repository-service php artisan make:repository UserRepository php artisan make:service UserService
✨ Features
- 🚀 Auto generate Repository and Service classes
- 📦 Base repository trait with common CRUD operations
- 🔧 Generate Repository or Service separately
- 💉 Dependency Injection ready
- 📝 Configurable namespaces and paths
- 🎯 PSR-4 compliant
- 🎨 Clean architecture friendly
🤔 Why use this package?
- Keep controllers clean and focused
- Separate business logic from controllers
- Improve code maintainability
- Make testing easier
- Follow clean architecture principles
📋 Requirements
- PHP ^8.0 or higher
- Laravel ^10.0 or ^11.0
- Composer
🔧 Installation
Install the package via Composer:
composer require mitul456/laravel-repository-service
Auto Discovery
This package supports Laravel auto-discovery. No need to manually register any service provider.
⚙️ Configuration
If you want to customize namespaces or paths, publish the config file:
php artisan vendor:publish --tag=repository-service-config
🚀 Usage
1. Create Repository and Service Together
php artisan make:repository-service User
📌 Example Usage
Repository Example
class UserRepository { public function getAll() { return User::all(); } }
Service Example
class UserService { protected $repository; public function __construct(UserRepository $repository) { $this->repository = $repository; } public function getUsers() { return $this->repository->getAll(); } }
Controller Example
class UserController extends Controller { protected $service; public function __construct(UserService $service) { $this->service = $service; } public function index() { return $this->service->getUsers(); } }
📁 Directory Structure
Example structure generated by the package:
app/
├── Repositories/
│ └── UserRepository.php
├── Services/
│ └── UserService.php
🧪 Testing
Run your Laravel tests:
php artisan test
⚠️ Troubleshooting
- Run
composer dump-autoloadif classes are not found - Ensure correct namespace configuration
- Check Laravel version compatibility
🤝 Contributing
Contributions are welcome!
- Fork the repository
- Create a new branch
- Make your changes
- Submit a pull request
📄 License
This package is open-sourced software licensed under the MIT license.