l0n3ly/laravel-repository-with-service

Repository and service pattern package for Laravel

Maintainers

Package info

github.com/idehen-divine/laravel-repository-with-service

Homepage

pkg:composer/l0n3ly/laravel-repository-with-service

Statistics

Installs: 11

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2026-04-18 09:55 UTC

This package is auto-updated.

Last update: 2026-04-18 10:01:54 UTC


README

Latest Version Total Downloads License Laravel Boost Compatible

A Laravel package that scaffolds the repository and service pattern โ€” generates repository and service classes with interfaces, and automatically binds them to their implementations via the container.

โœจ Features

  • ๐Ÿ—๏ธ Artisan Scaffolding - Generate repositories and services with make:repository and make:service
  • ๐Ÿ”— Auto Binding - Automatically binds interfaces to implementations via the service container
  • ๐Ÿ“ Subdirectory Support - Organize classes in nested directories (e.g., Admin/UserRepository)
  • ๐Ÿ”„ Paired Generation - Generate a repository and service together with a single command
  • ๐Ÿ“‹ Interface-First - Always generates a contract interface alongside each implementation
  • ๐ŸŽจ Multiple Templates - Choose between API service template or blank template
  • ๐Ÿค– Boost Compatible - Full support for Laravel Boost AI-powered workflows and Copilot skills

๐Ÿ“‹ Requirements

  • PHP ^8.2
  • Laravel 11, 12, or 13

๐Ÿ“ฆ Installation

Install the latest 1.x release:

composer require l0n3ly/laravel-repository-with-service

Publish the config file:

php artisan vendor:publish --tag=repository-with-service-config

Quick Start

Fastest Start: Generate Everything at Once

Scaffold a complete feature with one command:

php artisan make:model User --all

This creates everything โ€” model, migration, factory, seeder, controller, repository, and service.

Generate a Repository

# Basic repository
php artisan make:repository User

# Repository with paired service
php artisan make:repository User --service

# Repository with API-style service
php artisan make:repository User --service --api

# Repository in subdirectory
php artisan make:repository Admin/User --service

Generate a Service

# Basic service
php artisan make:service UserService

# API service with response helpers
php artisan make:service UserService --api

# Service with paired repository
php artisan make:service UserService --repository

# Minimal service
php artisan make:service UserService --blank

Generate from a Model

# Model with service and repository
php artisan make:model Product --service --repository

# Model with everything (fastest)
php artisan make:model Order --all

Use in Your Code

Services and repositories are automatically bound to the container:

class UserController extends Controller
{
    public function __construct(
        protected UserRepository $repository,
        protected UserService $service
    ) {}

    public function index()
    {
        return $this->service->getActiveUsers();
    }
}

๐Ÿ“– Documentation

Comprehensive documentation is available:

Document Purpose
Full Guide Installation, quick start, and all commands
API Reference Core interfaces and configuration
Troubleshooting Common issues and solutions
Examples Real-world usage examples
Contributing Contribution guidelines
Laravel Boost Integration Using with AI-powered Boost workflows

๐Ÿค– Laravel Boost Support

This package is fully integrated with Laravel Boost and provides three AI skills to enhance your development workflow:

Three Essential Skills

  • Repository Generator - Generate repositories with best practices
  • Service Generator - Generate services with business logic
  • Service Binding - Understand dependency injection and binding patterns

These skills are located in resources/boost/skills/ and are discovered by running:

php artisan boost:install --discover

Select the desired skills during installation, and they'll be available to your AI agent.

AI-Powered Workflows

Get intelligent suggestions for:

  • Generating complete feature modules
  • Creating repository hierarchies
  • Setting up service structures
  • Testing patterns and mocking

Example Boost Usage

User: "Generate a complete blog module with posts, comments, and categories"

Boost activates the skills and suggests:
โœ“ PostRepository with PostService (API template)
โœ“ CommentRepository with CommentService
โœ“ CategoryRepository with CategoryService
โœ“ BlogManager service orchestrating operations

Getting Started with Boost

  1. Install Laravel Boost in your Laravel project
  2. Run php artisan boost:install --discover
  3. Select this package's skills when prompted
  4. Ask your AI agent to generate repositories, services, or help with architecture

See BOOST.md for detailed integration guide.

๐ŸŽฏ Common Patterns

Blog Application

php artisan make:repository Post --service --api
php artisan make:repository Category --service
php artisan make:repository Post/Comment --service

E-Commerce

php artisan make:repository Product --service --api
php artisan make:repository Order --service --api
php artisan make:service Shop/Checkout --api
php artisan make:service Shop/Inventory --api

SaaS with Multi-Tenancy

php artisan make:repository Tenant --service --api
php artisan make:repository User --service --api
php artisan make:repository Subscription --service --api

See EXAMPLES.md for complete real-world examples.

๐Ÿ”ง Configuration

Edit config/service-repository.php to customize:

return [
    'repository_directory' => 'app/Repositories',
    'repository_namespace' => 'App\Repositories',
    'service_directory' => 'app/Services',
    'service_namespace' => 'App\Services',
    // ... naming conventions
];

Override Binding Example

Decorate or replace a bound implementation in your service provider:

$this->app->extend(UserRepository::class, function ($service, $app) {
    return new CachedUserRepository($service);
});

Service API Template

The --api flag generates services with response helpers:

class UserServiceImplement implements UserService
{
    use ResultService;

    public function create(array $data): array
    {
        try {
            $user = $this->repository->create($data);
            return $this->success($user, 'User created');
        } catch (Exception $e) {
            return $this->error($e->getMessage());
        }
    }
}

๐Ÿš€ Performance Tips

  1. Use Caching - Wrap repositories with caching decorators
  2. Eager Loading - Use Eloquent's with() in repositories
  3. Singleton Services - For stateless services, bind as singleton
  4. Optimize Queries - Focus repository methods on specific queries

๐Ÿงช Testing

Mock repositories in tests:

public function test_service_logic()
{
    $repository = Mockery::mock(UserRepository::class);
    $repository->shouldReceive('find')->with(1)->andReturn(['id' => 1]);

    $this->app->bind(UserRepository::class, fn() => $repository);

    $service = app(UserService::class);
    $result = $service->getUser(1);

    $this->assertEquals(1, $result['id']);
}

๐Ÿ“š Real-World Examples

Check EXAMPLES.md for complete implementations:

  • Blog with posts, comments, and categories
  • E-commerce checkout process
  • Multi-tenant SaaS structure
  • Admin dashboards
  • Testing patterns

๐Ÿค Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE.md for more information.

Support

  • ๐Ÿ“– Documentation: See docs/ directory
  • ๐Ÿ› Issues: Report on GitHub
  • ๐Ÿ’ฌ Discussions: Ask questions on GitHub Discussions
  • ๐Ÿ”ง Help: Check Troubleshooting Guide

Project guide:

Changelog

See CHANGELOG for release notes.

License

MIT. See LICENSE.md.