Download the PHP package jetcod/eloquent-repository without Composer
On this page you can find all versions of the php package jetcod/eloquent-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jetcod/eloquent-repository
More information about jetcod/eloquent-repository
Files in jetcod/eloquent-repository
Package eloquent-repository
Short Description This package is an implementation of repository pattern in laravel.
License MIT
Informations about the package eloquent-repository
Eloquent Repository Library
Requirements
- PHP ^8.0 or higher
- Laravel 9.0 or higher
- Eloquent 9.0 or higher
Installation
You can install the library using Composer:
Usage
To use the library, you need to create a repository class for each of your Eloquent models. You can either extend the Jetcod\LaravelRepository\Eloquent\BaseRepository class to get started or use artisan command to generate the repository class:
Here's an example of a UserRepository class:
In this example, the UserRepository extends the BaseRepository class and connects the repository to User mode by implementing getModelName()
method . You can then use the repository to perform CRUD operations on the User model, like this:
API
The following methods are available in the BaseRepository class:
find(int $id)
: Find a model by ID.findAll()
: Get all models.findBy(array $conditions, array $relations = [], bool $paginate = true, int $pageSize = 10)
: Find all models and their identified relations by conditions. The result can ne either paginated or return as a collection.findOneBy(array $conditions, array $relations = [])
: Find a model and its identified relations by conditions.with($relations, $callback = null)
: Set the relationships that should be eager loaded.countBy(array $conditions)
: Count models by conditions.delete($model)
: Delete a modelinsert(array $rows)
: Bulk insert datacreate(array $attributes)
: Create a new model.updateOrCreate(array $data, array $conditions)
: Create or update a record matching the attributes, and fill it with valuesupdate(Model $model, array $data, array $fillable = [])
: Update an existing model.fill(Model $model, array $data, array $fillable = [])
: Fill the given model by the given array of data.delete($model)
: Delete a model.destroy($ids)
: Destroy an array or collection of ids.query()
: Query builder instance.
You can also extend the BaseRepository * class to add custom methods for your specific use case.
Contributing
If you find any bugs or have ideas for new features, please open an issue or submit a pull request on GitHub.
License
My Eloquent Repository Library is open-sourced software licensed under the MIT license.
All versions of eloquent-repository with dependencies
illuminate/console Version ^8.0|^9.0|^10.0|^11.0
illuminate/database Version ^8.0|^9.0|^10.0|^11.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0
nesbot/carbon Version ^2.65