Laravel Repository design pattern implementation

Jagadesha NH
Jan 21, 2018 · 1 min read


There has been a lot of discussions about both the advantages and disadvantages of repository design pattern! Lets not get in to debate but lets dive in to the implementation.

Before reading further, in case you have no idea or never heard of repository design pattern, just read through this Microsoft article:

First create a new laravel project

laravel new project-name

Open the project in your favorite editor and create two new folders inside app directory and name them as, Repositories and Interfaces. Inside Interfaces directory will create a new UserInterface.php class

Next inside your Repositories folder create a new class called UserRepository.php, where we will be injecting User model.

Now finally create a controller called UserController in the default controllers directory, and Inject UserRepository

That’s all! You have implemented your first laravel repository pattern.

Jagadesha NH

Written by

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade