ymslavov / laravel-repository by ymslavov

Stateful repositories for Laravel models.
1,408
0
2
Package Data
Maintainer Username: ymslavov
Maintainer Contact: ymslavov@gmail.com (Yasen Slavov)
Package Create Date: 2016-10-12
Package Last Update: 2017-05-01
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 15:03:40
Package Statistics
Total Downloads: 1,408
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Stateful Repository Implementation

Based on the work featured in bosnadev.com, but with a few additional helpful methods for multi-record operations.

Laravel 5.3+ required.

Installation via Composer

composer require ymslavov/laravel-repository

Using Repository Generators

The package provides an easy way to generate repository classes for all models in the system.

All you need to do is register the service provider in your config/app.php in the 'providers' array:

'providers' => [
    ...other providers here...,
    YasenSlavov\LaravelRepository\Providers\LaravelRepositoryServiceProvider::class
]

And then use the following command in your command line tool:

php artisan repositories:generate

The script will scan the app/ directory for any classes that extend the Eloquent Model class and create repository classes for them.

Extending the AbstractRepository directly

If you prefer not to use the auto-generated classes, you can simply extend the AbstractRepository class directly from the package.

Example:

class UsersRepository extends AbstractRepository {
  /**
     * Specify the fully-qualified model name. Best use Classname::class
     *
     * @return string
     */
    function model()
    {
        return User::class;
    }
}


$usersRepo = \App::make(UsersRepository::class);

$usersWithTitleManager = $usersRepo
                            ->clearScope() //clear any state already established in the repo object
                            ->pushCriteria(new ByRoleTitle('Manager'))
                            ->all();