Member-only story

Laravel Repositories: A how-to example

Luís Nóbrega
4 min readJul 31, 2020

--

This layer can be between the domain and the database and provides access to data.

What are Repositories?

Photo by Nils Schirmer on Unsplash

Repositories are a Design Pattern, that provides access to data. This data could be stored in a database, file system, or external service.

They were introduced as part of the Domain-Driven Design in 2004, and want to provide an abstraction of data the application can use, like an interface to a collection.

Adding, removing, updating, and selecting items from the collection, through methods, without to deal with database or other concerns.

We want to achieve loose coupling, and keep the domain objects persistence ignorant.

His main idea is to create a bridge between models and controllers without having hard dependencies. But also, an useful design pattern on this topic is the service layer.

To know more about to structure the model layer in Laravel check this story on FAT logic to model layer.

What are the benefits?

--

--

Luís Nóbrega
Luís Nóbrega

Written by Luís Nóbrega

Web Developer at 25friday. Likes to travel, write and being a father.

No responses yet