Download the PHP package wendelladriel/laravel-more without Composer
On this page you can find all versions of the php package wendelladriel/laravel-more. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wendelladriel/laravel-more
More information about wendelladriel/laravel-more
Files in wendelladriel/laravel-more
Package laravel-more
Short Description Implementation of the Repository Pattern using Laravel Model binding
License MIT
Informations about the package laravel-more
Laravel MoRe
Implementation of the Repository Pattern using Laravel Model binding
The Repository Pattern
Repositories are used to wrap the logic to access the data sources of our applications. They can be used to improve the maintainability of an application by providing a central point in the code where the data sources are accessed.
Installation
You can publish the config file with:
Usage
This package provides a BaseRepository
class that you can extend to create your own Repositories.
Example:
By creating a class like the one above you will have access to all the methods below.
Get All Records
To get all the records you can use the getAll
method:
Examples:
Get All Records By Attribute
To get all the records matching an attribute you can use the getAllBy
method:
Examples:
Get Single Record By Attribute
To get a single record matching an attribute you can use the getBy
method:
Examples:
Get Single Record By Attribute Or Fail
To get a single record matching an attribute or throw an exception if no record is found
you can use the getByOrFail
method:
Examples:
Get Single Record By Params
To get a single record matching multiple attributes you can use the getByParams
method:
Examples:
Get Single Record By Params Or Fail
To get a single record matching multiple attributes or throw an exception if no record is found
you can use the getByParamsOrFail
method:
Examples:
Get All Records By Params
To get all the records matching multiple attributes you can use the getAllByParams
method:
Examples:
Update Records By Attribute
To update one or more records you can use the updateBy
method:
Examples:
Delete Records By Attribute
To delete one or more records you can use the deleteBy
method:
Examples:
Create New Record
To create a new record you can use the create
method:
Examples:
Disable Global Scope
If your model has a Global Scope and you need to disable it for any queries you can use the
disableGlobalScope
method:
Examples:
Enable Glogal Scope
If your model has a disabled Global Scope and you need to enable it again, you can use the
enableGlobalScope
method:
Examples:
Protected Helper Methods
Besides all public methods above the BaseRepository
also provides the following protected
methods that you can use in your Repositories classes:
Get Table Name
If you need to get the table name for the model binded to the repository you can use the
getTable
method:
Examples:
New Query Util
To create new queries you can use the newQuery
helper method:
Examples:
TO DO
- Create command to generate Repositories
- Create tests
Credits
- Wendell Adriel
- All Contributors
Contributing
All PRs are welcome.
For major changes, please open an issue first describing what you want to add/change.