herode / arepository
'A' Repository
dev-master / 1.0.x-dev
2019-05-02 08:12 UTC
Requires
- php: >=7.1.0
- ext-json: *
This package is auto-updated.
Last update: 2024-04-29 04:09:19 UTC
README
Install
Have two options to install, You can choose one of them:
1. If you want to use other project, You can:
-
Copy this folder
arepository
intomodules/arepository
into your root project -
Open file
composer.json
and edit
{
//...
"require": {
"herode/arepository": "*@dev",
},
"repositories": [
//...
{
"type": "path",
"url": "./modules/arepository"
}
]
//...
}
After run: composer dump-autoload
2. Install via composer
composer require herode/arepository
How to use
Run make new arepository
php artisan make:arepository [Name]
Example, you want to create new UserRepository
php artisan make:arepository User
Repository Interface
interface RepositoryInterface { /** * Retrieve data array for populate field select * * @param string $column * @param string|null $key * * @return \Illuminate\Support\Collection|array */ public function lists($column, $key = null); /** * Retrieve data array for populate field select * Compatible with Laravel 5.3 * @param string $column * @param string|null $key * * @return \Illuminate\Support\Collection|array */ public function pluck($column, $key = null); /** * Retrieve all data of repository * * @param array $columns * * @return mixed */ public function all($columns = ['*']); /** * Retrieve all data of repository, paginated * * @param null $limit * @param array $columns * * @return mixed */ public function paginate($limit = null, $columns = ['*']); /** * Find data by id * * @param $id * @param array $columns * * @return mixed */ public function find($id, $columns = ['*']); /** * Find data by field and value * * @param $field * @param $value * @param array $columns * * @return mixed */ public function findByField($field, $value, $columns = ['*']); /** * Find data by multiple fields * * @param array $where * @param array $columns * * @return mixed */ public function findWhere(array $where, $columns = ['*']); /** * Find data by multiple values in one field * * @param $field * @param array $values * @param array $columns * * @return mixed */ public function findWhereIn($field, array $values, $columns = ['*']); /** * Find data by excluding multiple values in one field * * @param $field * @param array $values * @param array $columns * * @return mixed */ public function findWhereNotIn($field, array $values, $columns = ['*']); /** * Save a new entity in repository * * @param array $attributes * * @return mixed */ public function create(array $attributes); /** * Update a entity in repository by id * * @param array $attributes * @param $id * * @return mixed */ public function update(array $attributes, $id); /** * Update or Create an entity in repository * * @param array $attributes * @param array $values * * @return mixed */ public function updateOrCreate(array $attributes, array $values = []); /** * Delete a entity in repository by id * * @param $id * * @return int */ public function delete($id); /** * Order collection by a given column * * @param string $column * @param string $direction * * @return $this */ public function orderBy($column, $direction = 'asc'); /** * Load relations * * @param $relations * * @return $this */ public function with($relations); /** * Load relation with closure * * @param string $relation * @param closure $closure * * @return $this */ public function whereHas($relation, $closure); /** * Add subselect queries to count the relations. * * @param mixed $relations * @return $this */ public function withCount($relations); /** * Set hidden fields * * @param array $fields * * @return $this */ public function hidden(array $fields); /** * Set visible fields * * @param array $fields * * @return $this */ public function visible(array $fields); /** * Query Scope * * @param \Closure $scope * * @return $this */ public function scopeQuery(\Closure $scope); /** * Reset Query Scope * * @return $this */ public function resetScope(); /** * Get Searchable Fields * * @return array */ public function getFieldsSearchable(); /** * Retrieve first data of repository, or return new Entity * * @param array $attributes * * @return mixed */ public function firstOrNew(array $attributes = []); /** * Retrieve first data of repository, or create new Entity * * @param array $attributes * * @return mixed */ public function firstOrCreate(array $attributes = []); }