Download the PHP package agungsugiarto/codeigniter4-repository without Composer
On this page you can find all versions of the php package agungsugiarto/codeigniter4-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agungsugiarto/codeigniter4-repository
More information about agungsugiarto/codeigniter4-repository
Files in agungsugiarto/codeigniter4-repository
Package codeigniter4-repository
Short Description Implementation of repository pattern for CodeIgniter 4. The package allows out-of-the-box filtering of data based on parameters in the request, and also allows you to quickly integrate the list filters and custom criteria.
License MIT
Informations about the package codeigniter4-repository
CodeIgniter4 Repository Pattern
About
Implementation of repository pattern for CodeIgniter 4. The package allows out-of-the-box filtering of data based on parameters in the request, and also allows you to quickly integrate the list filters and custom criteria.
Table of Contents
- Installation
- Configuration
- Overview
- Usage
- Create a Model
- Create a Repository
- Use built-in methods
- Create a Criteria
- Scope, Filter, and Order
Installation
Via Composer
Overview
Package allows you to filter data based on incoming request parameters:
It will automatically apply built-in constraints onto the query as well as any custom scopes and criteria you need:
Ordering by any field is available:
Package can also apply any custom criteria:
Usage
Create a Model
Create your model:
Create a Repository
Extend it from Fluent\Repository\Eloquent\BaseRepository
and provide entity()
method to return full model class name:
Use built-in methods
Available methods
-
Execute the query as a "select" statement or get all results:
-
Execute the query and get the first result:
-
Find a model by its primary key:
-
Add basic where clauses and execute the query:
-
Paginate the given query:
Note:
"paginate": {}
avaliable methods see docs -
Add an "order by" clause to the query:
-
Save a new model and return the instance:
-
Save a batch new model and return instance:
-
Update a record:
-
Update a batch record:
- Delete a record by id:
Create a Criteria
Criteria are a way to build up specific query conditions.
Multiple Criteria can be applied:
Scope, Filter and Order
In your repository define which fields can be used to scope your queries by setting $searchable
property.
Search by searchables:
Also several serchables enabled by default:
Enable ordering for specific fields by adding $orderable
property to your model class:
orderBy=email_desc
will order by email in descending order, orderBy=email
- in ascending
You can also build your own custom scopes. In your repository override scope()
method:
Create your scopes
class and extend ScopesAbstract
Now you can build any scopes you need:
License
Released under the MIT License, see LICENSE.