2017 © Pedro Peláez
 

library laravel-repositories

Model repositories for Laravel 5.

image

tmd/laravel-repositories

Model repositories for Laravel 5.

  • Friday, May 18, 2018
  • by antriver
  • Repository
  • 1 Watchers
  • 0 Stars
  • 71 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 46 Versions
  • 0 % Grown

The README.md

Laravel Repositories

The classes provided here allow you to use a repository pattern for CRUD operations on your Laravel models., (*1)

Installation

composer require antriver/laravel-repositories

Basic Usage

Create a class which extends AbstractRepository., (*2)

<?php

namespace App\Repositories;

use Antriver\LaravelRepositories\Base\AbstractRepository;
use App\Models\Post;

class PostRepository extends AbstractRepository
{
    public function getModelClass(): string
    {
        return Post::class;
    }
}

You now have a repository for Post models with the following methods:, (*3)

find(int $modelId)

Returns a single model by its primary key, or returns null., (*4)

findOrFail(int $modelId)

Returns a single model by its primary key, or throws a ModelNotFoundException., (*5)

findMany(array $modelIds)

Returns a collection of multiple models. The result will only contain the models that were found., (*6)

findOneBy(string $field, $value)

Returns a single model where field matches value, or returns null., (*7)

findOneByOrFail(string $field, $value)

Returns a single model where field matches value, or throws a ModelNotFoundException., (*8)

persist(Model $model)

Save the given model to the database., (*9)

remove(Model $model)

Delete the given model from the database., (*10)

incremenet(Model $model, $column, $amount)

Increase the value in the given column by the amount specified., (*11)

(i.e. UPDATE table SET column = column + 1);, (*12)

decrement(Model $model, $column, $amount)

Decrease the value in the given column by the amount specified., (*13)

(i.e. UPDATE table SET column = column - 1);, (*14)

Caching Repository

If you extend AbstractCachedRepository instead of AbstractRepository you will have all the same functions, however the following operations will look in a cache for the model first. - find - Caches the model by its primary key. - findOrFail - Caches the model by its primary key. - findMany - Uses the same cache keys are find to locate each model. - findOneBy - Caches the primary key of the model found with the matching value. Future calls will look up the matching ID for the value and then call find. - findOneByOrFail - Caches the primary key of the model found with the matching value. Future calls will look up the matching ID for the value and then call find., (*15)

  • persist - This will also store the model in the cache after it is saved to the database.
  • remove - This will also remove the model from the cache after it is saved to the database.

The caching repository also has these additional methods:, (*16)

forgetById(int $modelId)

Forgets a cached copy of a model (does not delete it from a database)., (*17)

forgetByModel(Model $model)

Forgets a cached copy of a model (does not delete it from a database)., (*18)

refreshById(int $modelId)

Updates the cached copy of a model with the latest version found in the database., (*19)

Soft Deletable Repository

If your model supports soft deletes (Illuminate\Database\Eloquent\SoftDeletes trait), the find etc. methods above will exclude soft deleted models from the results., (*20)

If you extend AbstractSoftDeletableRepository instead of AbstractRepository you will get these additional methods:, (*21)

findWithTrashed(int $modelId)

findWithTrashedOrFail(int $modelId)

Returns a single model by primary key even if it has been soft-deleted., (*22)

findTrashed(int $modelId)

findTrashedOrFail(int $modelId)

Returns a model by primary key only if it has been soft-deleted., (*23)

findOneByWithTrashed(string $field $value)

findOneByWithTrashedOrFail(string $field, $value)

Returns a single model where field matches value even if it has been soft-deleted., (*24)

findTrashedOneBy(string $field $value)

findTrashedOneByOrFail(string $field, $value)

Returns a single model where field matches value only if it has been soft-deleted., (*25)

Caching Soft Deletable Repository

This combines the functionality of AbstractCachedRepository and AbstractSoftDeletableRepository., (*26)

When using this, the cache of models will be populated with soft-deleted models too. This applies to the primary key cache and the field/value cache. There is filtering inside the repository to return null/throw as appropriate if a trashed or not-trashed model is requested., (*27)

The Versions

18/05 2018

dev-master

9999999-dev

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

18/05 2018

2.2.2

2.2.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

2.2.1

2.2.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

25/01 2018

2.2.0

2.2.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/01 2018

2.1.2

2.1.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

2.1.1

2.1.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

2.1.0

2.1.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

2.0.2

2.0.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

2.0.1

2.0.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2017

2.0.0

2.0.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

12/07 2017

1.6.4

1.6.4.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/03 2017

1.6.3

1.6.3.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/02 2017

1.6.2

1.6.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/02 2017

1.6.1

1.6.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/02 2017

1.6.0

1.6.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

13/02 2017

1.5.9

1.5.9.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/01 2017

1.5.8

1.5.8.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/12 2016

1.5.7

1.5.7.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

1.5.6

1.5.6.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

06/12 2016

1.5.5

1.5.5.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

1.5.4

1.5.4.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

1.5.3

1.5.3.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/12 2016

1.5.2

1.5.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

28/11 2016

1.5.1

1.5.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

23/11 2016

1.5

1.5.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

The Development Requires

22/11 2016

1.4.4

1.4.4.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

16/11 2016

1.4.3

1.4.3.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

09/11 2016

1.4.2

1.4.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

03/11 2016

1.4.1

1.4.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

03/11 2016

1.4.0

1.4.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.3.4

1.3.4.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.3.3

1.3.3.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.3.2

1.3.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.3.1

1.3.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.3.0

1.3.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

02/11 2016

1.2.3

1.2.3.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

25/10 2016

1.2.2

1.2.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

25/10 2016

1.2.1

1.2.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

25/10 2016

1.2.0

1.2.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

24/10 2016

1.1.2

1.1.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

23/10 2016

1.1.1

1.1.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

23/10 2016

1.1.0

1.1.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

17/10 2016

1.0.2

1.0.2.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

17/10 2016

1.0.1

1.0.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

17/10 2016

1.0.0

1.0.0.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires

 

10/10 2016

0.0.1

0.0.1.0

Model repositories for Laravel 5.

  Sources   Download

MIT

The Requires