Download the PHP package smashed-egg/laravel-model-repository without Composer
On this page you can find all versions of the php package smashed-egg/laravel-model-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smashed-egg/laravel-model-repository
More information about smashed-egg/laravel-model-repository
Files in smashed-egg/laravel-model-repository
Package laravel-model-repository
Short Description Add support for Model Repositories to Laravel
License MIT
Informations about the package laravel-model-repository
Laravel Model Repository
This package provides a Repository class for people who like SOLID principles (Separation of concerns and all that jazz) and want their repository logic in a different class.
Requirements
- PHP 8.0.2+
- Laravel 9.0+
Installation
To install this package please run:
You can publish a configuration file that comes with the package:
Support Me
Do you like this package? Does it improve you're development. Consider sponsoring to help with future development.
Thank you!
Usage
Configuration (optional)
If you have published the config file (located at config/smashed_egg/model_repository.php) you can override the base repository class used with the make command, as well as a model to repository mapping, which is useful when using the RepositoryManager class (more on that later).
Creating a Model Repository
You can run the following command to create a new Repository for your Model, assuming you already have a User model:
or using the command alias:
You can even override the base repository class
Out of the box you get access to the following methods, that will pass along to the Model instance:
- save(Model $model)
- delete(Model $model, bool $force = false) - When using the SoftDeletes trait you can control whether you want to soft or hard delete
- restore(Model $model) - When using the SoftDeletes trait you can undo a soft deletion
- query - Start an eloquent query
- baseQuery - Start a database query
Using the RepositoryManager
If you have configured a model to repository mapping
All versions of laravel-model-repository with dependencies
illuminate/console Version ^9.21|^10.0
illuminate/contracts Version ^9.21|^10.0
illuminate/support Version ^9.21|^10.0