Download the PHP package littlebug/laravel-repository without Composer
On this page you can find all versions of the php package littlebug/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download littlebug/laravel-repository
More information about littlebug/laravel-repository
Files in littlebug/laravel-repository
Package laravel-repository
Short Description The repository mode for laravel!
License MIT
Homepage https://littlebug.vip
Informations about the package laravel-repository
laravel-repository
Usage of Repository
Introduction
laravel-repository
provides the basic repository
class for laravel
model The package was made to provide more
More external methods, and more friendly editor prompts; layering the code, repository
is
responsible for external business logic processing, model
is only responsible for the definition
of the fields, attributes, query conditions, and return values of the data table. It does not
participate in specific logical operations, and does not serve the control layer.
Relative to the direct use of model
advantages:
- Solve the problem that
model
does not automatically handle extra fields when adding or modifying - Optimize chained calls for
model
queries, query directly using arrays - Automatically process corresponding associated data queries through query conditions and query fields
- Provides a more friendly editor prompt
Install
Installation requirements
- PHP >= 7.0.0
- Laravel >= 5.5.0
1.1 Install package
or add this to require section in your composer.json file:
then run composer update
1.2 Use the command to generate model
and repository
Suppose you have users in your database, or you replace users with the table names in your database.
The command will be at:
- Generate
User
file underapp/Models/
file - Generate
UserRepository
file underapp/Repositories/
file
1.3 Using repository
in the controller
In addition to the injection method invocation described above, you can also use static method invocation; As follows:
1.4 Other common methods
Retrieve the data
method name | return value | description |
---|---|---|
find($conditions, $columns = ['*']) |
null\|array |
Querying individual data |
findBy($conditions, $column) |
null\|mixed |
Query a single field for a single piece of data |
findAll($conditions, $columns = ['*]) |
array |
Query multiple data |
findAllBy($conditions, $column) |
array |
Querying a single field array of multiple data |
first($conditions, $column) |
null\|model |
Retrieve a single model |
get($conditions, $column) |
Collection |
Retrieve the collection |
Statistical query
method name | return value | description |
---|---|---|
count($conditions, $column = '*') |
int |
The number of statistical |
max($conditions, $column) |
mixed |
The maximum |
min($conditions, $column) |
mixed |
The minimum value |
avg($conditions, $column) |
mixed |
The average |
sum($conditions, $column) |
mixed |
sum |
Create or modify data
method name | return value | description |
---|---|---|
increment($conditions, $column, $amount = 1, $extra = []) |
int |
Since the increase |
decrement($conditions, $column, $amount = 1, $extra = []) |
int |
Since the reduction of |
firstOrCreate(array $attributes, array $value = []) |
model |
The query does not exist so create |
updateOrCreate(array $attributes, array $value = []) |
model |
Modifications do not exist so create |
1.5 More documentation
Please check more about repository
More code generation commands
Commands support specifying database connections such as --table=dev.users
-
core:model
generatesmodel
class files andrepository
class files by querying database table information. -
core:repository
generates therepository
class file core:request
generatesrequest
verification class file by querying database table information
Command Parameter Details
thanks for jinxing.liu and seven 💐🌹
if my repository is helpful to you, give me a star to encourage me~ ✨, I will continue to maintain this project.
All versions of laravel-repository with dependencies
ext-json Version *