Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-repositories

> 后端框架
Open source

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Lar

669 stars0 likes2 views
WebsiteGitHub

About

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Lar

Rinvex Repository

⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️

Contact me if you are interested in maintaining it!

Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain. If you are looking for Laravel 5.5 support, use the dev-develop branch. It's stable but not tagged yet since test suites isn't complete.

Features

  • Cache, Cache, Cache!
  • Prevent code duplication.
  • Reduce potential programming errors.
  • Granularly cache queries with flexible control.
  • Apply centrally managed, consistent access rules and logic.
  • Implement and centralize a caching strategy for the domain model.
  • Improve the code’s maintainability and readability by separating client objects from domain models.
  • Maximize the amount of code that can be tested with automation and to isolate both the client object and the domain model to support unit testing.
  • Associate a behavior with the related data. For example, calculate fields or enforce complex relationships or business rules between the data elements within an entity.

Quick Example (TL;DR)

The Rinvex\Repository\Repositories\BaseRepository is an abstract class with bare minimum that concrete implementations must extend.

The Rinvex\Repository\Repositories\EloquentRepository is currently the only available repository implementation (more to come in the future and you can develop your own), it makes it easy to create new eloquent model instances and to manipulate them easily. To use EloquentRepository your repository MUST extend it first:

php
namespace App\Repositories;

use Rinvex\Repository\Repositories\EloquentRepository;

class FooRepository extends EloquentRepository
{
    protected $repositoryId = 'rinvex.repository.uniqueid';

    protected $model = 'App\Models\User';
}

That's it, you're done! Yes, it's that simple.

But if you'd like more control over the container instance, or would like to pass model name dynamically you can alternatively do as follow:

php
namespace App\Repositories;

use Illuminate\Contracts\Container\Container;
use Rinvex\Repository\Repositories\EloquentRepository;

class FooRepository extends EloquentRepository
{
    // Instantiate repository object with required data
    public function __construct(Container $container)
    {
        $this->setContainer($container)
             ->setModel(\App\Models\User::class)
             ->setRepositoryId('rinvex.repository.uniqueid');

    }
}

Now inside your controller, you can either instantiate the repository traditionally through $repository = new \App\Repositories\FooRepository(); or to use Laravel's awesome dependency injection and let the IoC do the magic:

php
namespace App\Http\Controllers;

use App\Repositories\FooRepository;

class BarController
{
    // Inject `FooRepository` from the IoC
    public function baz(FooRepository $repository)
    {
        // Find entity by primary key
        $repository->find(1);

        // Find all entities
        $repository->findAll();

        // Create a new entity
        $repository->create(['name' => 'Example']);
    }
}

Rinvex Repository Workflow - Create Repository

Rinvex Repository Workflow - Use In Controller

UML Diagram


Mission accomplished! You're good to use this package right now! :white_check_mark:

Unless you need to dig deeper & know some advanced stuff, you can skip the following steps! :wink:


Table Of Contents

  • Installation
    • Compatibility
    • Require Package
    • Install Dependencies
  • Integration
    • Native Integration
    • Laravel Integration
  • Configuration
  • Usage
    • Quick Example
    • Detailed Documentation
      • setContainer(), getContainer()
      • setConnection(), getConnection()
      • setModel(), getModel()
      • setRepositoryId(), getRepositoryId()
      • setCacheLifetime(), getCacheLifetime()
      • setCacheDriver(), getCacheDriver()
      • enableCacheClear(), isCacheClearEnabled()
      • createModel()
      • forgetCache()
      • with()
      • where()
      • whereIn()
      • whereNotIn()
      • whereHas()
      • offset()
      • limit()
      • orderBy()
      • find()
      • findBy()
      • findFirst()
      • findAll()
      • paginate()
      • simplePaginate()
      • findWhere()
      • findWhereIn()
      • findWhereNotIn()
      • findWhereHas()
      • create()
      • update()
      • store()
      • delete()
      • beginTransaction()
      • commit()
      • rollBack()
    • Code To An Interface
    • Add Custom Implementation
    • EloquentRepository Fired Events
    • Mandatory Repository Conventions
    • Automatic Guessing
    • Flexible & Granular Caching
      • Whole Application Cache
      • Individual Query Cache
      • Temporary Skip Individual HTTP Request Cache
  • Final Thoughts
  • Changelog
  • Support
  • Contributing & Protocols
  • Security Vulnerabilities
  • About Rinvex
  • License

Installation

The best and easiest way to install this package is through Composer.

Compatibility

This package fully compatible with Laravel 5.1.*, 5.2.*, and 5.3.*.

While this package tends to be framework-agnostic, it embraces Laravel culture and best practices to some extent. It's tested mainly with Laravel but you still can use it with other frameworks or even without any framework if you want.

Require Package

Open your application's composer.json file and add the following line to the require array:

json
"rinvex/laravel-repositories": "3.0.*"

Note: Make sure that after the required changes your composer.json file is valid by running composer validate.

Install Dependencies

On your terminal run composer install or composer update command according to your application's status to install the new requirements.

Note: Checkout Composer's Basic Usage documentation for further details.

Integration

Rinvex Repository package is framework-agnostic and as such can be integrated easily natively or with your favorite framework.

Native Integration

Integrating the package outside of a framework is incredibly easy, just require the vendor/autoload.php file to autoload the package.

Note: Checkout Composer's Autoloading documentation for further details.

Run the following command on your terminal to publish config files:

bash
php artisan vendor:publish --tag="rinvex-repository-config"

Note: Checkout Laravel's Configuration documentation for further details.

You are good to go. Integration is done and you can now use all the available methods, proceed to the Usage section for an example.

Configuration

If you followed the previous integration steps, then your published config file reside at config/rinvex.repository.php.

Config options are very expressive and self explanatory, as follows:

…

Usage

Detailed Documentation

setContainer(), getContainer()

The setContainer method sets the IoC container instance, while getContainer returns it:

php
// Set the IoC container instance
$repository->setContainer(new \Illuminate\Container\Container());

// Get the IoC container instance
$container = $repository->getContainer();

setConnection(), getConnection()

The setConnection method sets the connection associated with the repository, while getConnection returns it:

php
// Set the connection associated with the repository
$repository->setConnection('mysql');

// Get the current connection for the repository
$connection = $repository->getConnection();

Note: The name passed to the setConnection method should correspond to one of the connections listed in your config/database.php configuration file.

setModel(), getModel()

The setModel method sets the repository model, while getModel returns it:

php
// Set the repository model
$repository->setModel(\App\Models\User::class);

// Get the repository model
$repositoryModel = $repository->getModel();

setRepositoryId(), getRepositoryId()

The setRepositoryId method sets the repository identifier, while getRepositoryId returns it (it could be anything you want, but must be unique per repository):

php
// Set the repository identifier
$repository->setRepositoryId('rinvex.repository.uniqueid');

// Get the repository identifier
$repositoryId = $repository->getRepositoryId();

setCacheLifetime(), getCacheLifetime()

The setCacheLifetime method sets the repository cache lifetime, while getCacheLifetime returns it:

php
// Set the repository cache lifetime
$repository->setCacheLifetime(123);

// Get the repository cache lifetime
$cacheLifetime = $repository->getCacheLifetime();

setCacheDriver(), getCacheDriver()

The setCacheDriver method sets the repository cache driver, while getCacheDriver returns it:

php
// Set the repository cache driver
$repository->setCacheDriver('redis');

// Get the repository cache driver
$cacheDriver = $repository->getCacheDriver();

enableCacheClear(), isCacheClearEnabled()

The enableCacheClear method enables repository cache clear, while isCacheClearEnabled determines it's state:

php
// Enable repository cache clear
$repository->enableCacheClear(true);

// Disable repository cache clear
$repository->enableCacheClear(false);

// Determine if repository cache clear is enabled
$cacheClearStatus = $repository->isCacheClearEnabled();

createModel()

The createModel() method creates a new repository model instance:

php
$repositoryModelInstance = $repository->createModel();

forgetCache()

The forgetCache() method forgets the repository cache:

php
$repository->forgetCache();

with()

The with method sets the relationships that should be eager loaded:

php
// Pass a string
$repository->with('relationship');

// Or an array
$repository->with(['relationship1', 'relationship2']);

where()

The where method adds a basic where clause to the query:

php
$repository->wher

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPcacheeloquentgranularlaravel

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架