vivek-mistry/repository-interface

Laravel package for dependency injection to separate business logic.

Installs: 75

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/vivek-mistry/repository-interface

1.0.1 2025-09-27 15:06 UTC

This package is auto-updated.

Last update: 2025-10-02 15:06:05 UTC


README

A Laravel package that leverages dependency injection to cleanly separate business logic from other application layers, promoting better code organization, testability, and adherence to SOLID principles

🛠️ Installation

Install the package via Composer:

composer require vivek-mistry/repository-interface

Get Plain Repository Interface

php artisan app:make-repo {ModelName} --plain

Particular Model Generate the Repository-Interface

php artisan app:make-repo {ModelName}

With basic functions you will get here like,

  • public function createOrUpdate(array $data, $id = null);
  • public function getAll($draw = null, $start = null, $rawperpage = null);
  • public function getRecordById($id, array $with = []);
  • public function getRecordByField(string $field_name, string $field_value);

So using above two files created at app/Repositories/Interface & app/Repositories/Repository

  • ModelNameInterface.php
  • ModelNameInterfaceRepository.php

Create Service Prvider

php artisan make:provider RepositoryServiceProvider

Register Your Service Provider & register your repository

=> Register your service provider

=> In your RepositoryServiceProvider add below :

    public function boot(): void
    {
        $this->app->bind(
            INTERFACE_NAME::class,
            REPOSITORY_NAME::class
        );
    }

HOW TO USE IN YOUR CONTROLLER?

For example :

class UserController extends Controller
{
    protected $userRepository;

    /**
     * Load Repository
     */
    public function __construct(
        UserRepositoryInterface $userRepository
    ) {
        $this->userRepository = $userRepository;
    }

    public function index($request)
    {
        $data = [
            'name' => $request->name,
            'email' => $request->email
        ];
        $this->userRepository->createOrUpdate($data);
    }
}

Testing

composer test

Change Logs

Date : 27 Sept, 2025

  • Update the Minor bugs of functions
  • Added Plain Repository/Interface

Credits

License

MIT License. See LICENSE for details.