Are you tired of manually binding interfaces to implementations in Laravel? Or creating the same service and repository boilerplate over and over?
Meet Contract Resolver, a Laravel package that handles this for you โ cleanly and automatically.
๐ฏ What Is It?
Contract Resolver helps you follow Laravel's Repository + Service pattern by:
- Auto-binding interfaces to implementations
- Generating services/repositories/interfaces using artisan commands
- Supporting nested namespaces
- Requiring zero dependencies
๐ง Installation
composer require takielias/contract-resolver
Optionally publish the config file:
php artisan vendor:publish --provider="TakiElias\ContractResolver\ContractResolverServiceProvider" --tag="contract-resolver.config"
โจ Artisan Commands
You can generate everything interactively:
php artisan cr:make
Or individually:
php artisan cr:make-repo Product
php artisan cr:make-service Product
It also supports nested paths:
php artisan cr:make-repo Admin\\User
๐ Convention-Based Binding
Just follow this structure:
app/
โโโ Contracts/
โ โโโ Repositories/
โ โโโ UserRepositoryInterface.php
โโโ Repositories/
โ โโโ UserRepository.php
And the binding happens automatically! You can inject interfaces like:
public function __construct(UserRepositoryInterface $userRepo) {
$this->userRepo = $userRepo;
}
๐งช Testing
Run tests:
composer test
With coverage:
composer test-coverage
๐ Why Use It?
โ
Clean, testable Laravel apps
โ
Focus more on business logic
โ
No need to manually bind contracts
โ
Fully customizable
๐ Links
- ๐ธ GitHub: https://github.com/takielias/contract-resolver
- ๐ธ Packagist:
takielias/contract-resolver
If you find this useful, give it a โญ on GitHub. I'd love your feedback or contributions!
Top comments (0)