Download the PHP package lerouse/laravel-repository without Composer
On this page you can find all versions of the php package lerouse/laravel-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lerouse/laravel-repository
More information about lerouse/laravel-repository
Files in lerouse/laravel-repository
Package laravel-repository
Short Description Repository implementation for Laravel.
License MIT
Informations about the package laravel-repository
Laravel Model Repository
Model Repository implementation for the Laravel framework ^v6.0 and above.
This package provides a structured framework to begin implementing a simple Model Repository structure in an existing Laravel application.
Installation
The recommended method to install LaravelRepository is with composer
Laravel without auto-discovery
If you don't use auto-discovery, add the ServiceProvider to the providers array in config/app.php
Package configuration
Copy the package configuration to your local config directory.
Usage
Model Repository Location
By default Laravel Model Repository presumes that model repositories are stored in the directory
app/repositories/model
. If you would like to change the directory your model repositories are stored change the namespace
variable in the config/repostiory.php
config file.
For example if your model repositories are located in app/model/repositories
update the namespace to
Creating a Repository
Repositories should extend the Lerouse\LaravelRepository\EloquentRepository
method and implement the builder method
which should return an instance of a Illuminate\Database\Eloquent\Builder
.
The following methods are available out of the box:-
Method | Return Type | Description |
---|---|---|
Collection | Get all Models | |
LengthAwarePaginator | Get all models as Paginated Results | |
Model | Find a Model by its Primary Key | |
Collection | Find a collection of Models by their Primary Keys | |
Model | Create a new Model | |
Boolean | Create a collection of new Models | |
Model | Update a Model by its Primary Key | |
Boolean | Update a collection of Models | |
Model/null | Delete a Model by its Primary Key | |
void | Delete a collection of Models by their Primary Keys |
Using a Repository
Repositories can be used directly (see above for available built in methods).
Extending a Repository
Repositories should be the single point for extending/amending queries to your models. The advantage of this is all of your model business logic is in a single location. See below a repository that contains commonly used extended functionality as well as some custom methods that are also used.
Laravel Route Model Binding
Laravel route model binding provides a convenient way to automatically inject the model instances directly into your routes. To force the route model binding to use your repository rather than the model itself you can add the trait to your model.
Now when you utilise Laravel's Route Model Binding, the find method on the repository will be used.
Please Note: The repositories location is determined via the namespace variable in the config/repostiory.php
config file.
License
Laravel Model Repository is free software distributed under the terms of the MIT license.
All versions of laravel-repository with dependencies
ext-json Version *
illuminate/contracts Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/events Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/database Version ^6.0|^7.0|^8.0|^9.0|^10.0
illuminate/support Version ^6.0|^7.0|^8.0|^9.0|^10.0
laravel/legacy-factories Version ^1.2