knash94-repositories
Repositories is a package for Laravel that makes it much easier to create repositories for Laravel, whether you want just a Eloquent repository or an eloquent repository with cache., (*1)
Installation
Run the following command from your terminal, (*2)
composer require knash94/repositories
Open app/config with your favorite text editor and add the following line under package service providers, (*3)
Knash94\Repositories\RepositoryServiceProvider::class,
Usage
To create a basic repository without cache, (*4)
php artisan make:repository exampleRepository
or with cache, (*5)
php artisan make:repository exampleRepository --with-cache
Afterwards, open the new generated file under app/repositories/exampleRepository.php and find, (*6)
protected $model;
and replace it with your models class, for example, (*7)
protected $model = User::class;
After that you're all ready to go!, (*8)
Repository methods
public function all();
public function count();
public function countWhere($column, $value);
public function findById($id);
public function updateById($id, array $attributes);
public function create(array $attributes);
public function get();
public function groupBy($columns);
public function limit($limit);
public function orderBy($column, $direction = 'asc');
public function select($columns = ['*']);
public function where($column, $operator = null, $value = null, $boolean = 'and');
public function createMultiple(array $data);
public function with($relations);