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)