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-12-22 15:03:39 |
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 |
Based on the work featured in bosnadev.com, but with a few additional helpful methods for multi-record operations.
Laravel 5.3+ required.
composer require ymslavov/laravel-repository
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.
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();