LaravelPackages.net
Acme Inc.
Toggle sidebar
ymslavov/laravel-repository

Stateful repositories for Laravel models.

1.408
0
3.0
About ymslavov/laravel-repository

ymslavov/laravel-repository is a Laravel package for stateful repositories for laravel models.. It currently has 0 GitHub stars and 1.408 downloads on Packagist (latest version 3.0). Install it with composer require ymslavov/laravel-repository. Discover more Laravel packages by ymslavov or browse all Laravel packages to compare alternatives.

Last updated

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();

Comments