Download the PHP package prettus/laravel-repository without Composer
On this page you can find all versions of the php package prettus/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download prettus/laravel-repository
More information about prettus/laravel-repository
Files in prettus/laravel-repository
Package laravel-repository
Short Description Repositories to abstract the database layer
License MIT
Informations about the package laravel-repository
This package is abandoned and no longer maintained. The author suggests using the https://github.com/andersao/l5-repository package instead.
Laravel 4 - Repositories
Laravel 4 Repositories is used to abstract the data layer, making our application more flexible to maintain.
Installation
Add this line "prettus/laravel-repository": "2.0.*" in your composer.json.
Issue composer update
Add to app/config/app.php service provider array:
Publish Configuration
Methods
Repository
- scopeReset()
- find($id, $columns = ['*'])
- findByField($field, $value, $columns = ['*'])
- all($columns = array('*'))
- paginate($limit = null, $columns = ['*'])
- create(array $attributes)
- update(array $attributes, $id)
- delete($id)
- getModel()
- with(array $relations);
- pushCriteria(Criteria $criteria)
- getCriteria()
- getByCriteria(Criteria $criteria)
- skipCriteria()
Criteria
- apply($query)
Usage
Create a Model
Create your model normally , but it is important to define the attributes that can be filled from the input form data.
Create a Repository
Use methods
Find all results in Repository
Find all results in Repository with pagination
Find by result by id
Create new entry in Repository
Update entry in Repository
Delete entry in Repository
Create a Criteria
Criteria is a way to change the repository of the query by applying specific conditions according to their need . You can add multiple Criteria in your repository
Using the Criteria in a Controller
Getting results from criteria
Setting Criteria default in Repository
Skip criteria defined in the repository
Use skipCriteria before any method in the repository
Using the RequestCriteria
RequestCriteria is a standard Criteria implementation. It enables filters perform in the repository from parameters sent in the request.
You can perform a dynamic search , filtering the data and customize queries
To use the Criteria in your repository , you can add a new criteria in the boot method of your repository , or directly use in your controller , in order to filter out only a few requests
Enabling in your Repository
Remember, you need to define which fields from the model can are searchable.
In your repository set $fieldSearchable with their fields searchable.
You can set the type of condition will be used to perform the query , the default condition is "="
Enabling in your Controller
Example the Crirteria
Request all data without filter by request
Conducting research in the repository
http://prettus.local/users?search=Anderson%20Andrade
or
http://prettus.local/users?search=Anderson&searchFields=name:like
or
http://prettus.local/[email protected]&searchFields=email:=
Filtering fields
http://prettus.local/users?filter=id;name
Sorting the results
http://prettus.local/users?filter=id;name&orderBy=id&sortedBy=desc
Overwrite params name
You can change the name of the parameters in the configuration file config/repository-criteria.php
Author
Anderson Andrade - [email protected]