Download the PHP package elegantmedia/laravel-simple-repository without Composer
On this page you can find all versions of the php package elegantmedia/laravel-simple-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download elegantmedia/laravel-simple-repository
More information about elegantmedia/laravel-simple-repository
Files in elegantmedia/laravel-simple-repository
Package laravel-simple-repository
Short Description Lightweight Repository pattern for Laravel 10 projects. Includes a repository generator.
License MIT
Homepage https://github.com/elegantmedia/laravel-simple-repository
Informations about the package laravel-simple-repository
Laravel Simple Repository
Simple repository pattern for Laravel's Eloquent models.
Why Repositories?
You can still use Eloquent queries to fetch models directly. Purpose of Repositories are to offer a standard API (or an interface), so you have a reliable layer between ORM and the controllers. This will reduce duplication and keep code clean on large applications.
Here's an example where why you may need this.
Finding an Eloquent Model by id. Here you limit column names retrived from database.
You can also do it with a repository, but to fetch relationships (which is a lot more common in large applications).
Then on the repository, you can add some common checks such as checking authorisation, filtering data based on what you retrieve etc.
Install
Install via Composer
Usage
Repository Generator
Create a new repository with make:repository
command. By default, they'll be stored in Models
directory.
The following options are also available.
By default, the the related model will be guessed. For example, if you're creating CarsRepository
we can assume the associated model will be Car
in the same directory. But if you want to change it, you can pass that as an argument.
To keep folders clean, you can group the Model+Repository to a single folder.
When you do this, a new plural directory will be automatically created. For example, Cars
in this example. The file structure can look like this.
Search
Model
To add basic SQL LIKE
search to a model, add the SearchableLike
trait to a model.
Now you can do SQL based keyword searches on Models directly.
Repository
You can call search
on a repository to build advanced reusable filters.
First, setup the repository
Then call search on your repository. Usually this happens from a controller or a parent repository.
Because the SearchFilter is a query itself, you can use it to chain conditions.
The default filter will add q
from query string, and sort results in descending order. If you don't want that, create a filter without the defaults.
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and for details.
Credits
- Elegant Media
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-simple-repository with dependencies
illuminate/console Version ^10.0
illuminate/database Version ^10.0
illuminate/support Version ^10.0