I'm not a big fan of the repository pattern in Laravel apps, even in a big ones – when working in a team. It's a hard concept to do right. If done wrong it does more harm than good; it's hard to maintain, hard to refactor and hard to change behaviour. Laravel has a great way to write custom query builders to extract business logic. Great for querying models. For writing models I would suggest using Action Closes. One example of them can be found in Jetstream's sourcecode . Actions are great to test in isolation and link to user stories. Answer from Becksteen on reddit.com
🌐
Medium
soulaimaneyh.medium.com › laravel-repository-pattern-da4e1e3efc01
PHP Laravel Repository Pattern. The Repository Pattern is a software… | by Soulaimane YAHYA | Medium
February 28, 2025 - To implement the Repository Pattern in Laravel, we need to follow these steps: First, we need to create an interface that defines the methods that will be used to interact with the data storage mechanism. For example, let’s create an interface for a User repository: <?php namespace App\Repositories; use App\Models\User; interface UserRepositoryInterface { public function all(): \Illuminate\Database\Eloquent\Collection; public function create(array $data): ?User; public function update(array $data, int $id): int; public function delete(int $id): bool; public function find(int $id): ?User; }
🌐
Twilio
twilio.com › en-us › blog › repository-pattern-in-laravel-application
How to Use the Repository Pattern in a Laravel Application | Twilio
January 26, 2024 - Modern PHP frameworks, such as Laravel and Symfony, interact with databases via Object-relational mappers (ORMs); Symfony uses Doctrine as its default ORM and Laravel uses Eloquent. Both take different approaches in how database interaction works. With Eloquent, Models are generated for each database table, forming the basis of interaction. Doctrine, however, uses the Repository pattern where each Entity has a corresponding repository containing helper functions to interact with the database.
Discussions

Is using the repository pattern best practise?
I'm not a big fan of the repository pattern in Laravel apps, even in a big ones – when working in a team. It's a hard concept to do right. If done wrong it does more harm than good; it's hard to maintain, hard to refactor and hard to change behaviour. Laravel has a great way to write custom query builders to extract business logic. Great for querying models. For writing models I would suggest using Action Closes. One example of them can be found in Jetstream's sourcecode . Actions are great to test in isolation and link to user stories. More on reddit.com
🌐 r/laravel
40
22
January 29, 2023
php - Laravel - Using the Repository Pattern - Stack Overflow
I am trying to learn the repository pattern, and seem to have got myself a tad confused with how I can use this repository pattern when eager loading relationships and keep db logic out of my contr... More on stackoverflow.com
🌐 stackoverflow.com
Mastering the Service-Repository Pattern in Laravel
I’m absolutely sick of seeing the “repository” pattern advocated for Laravel apps, and then all they do is proxy calls to Eloquent models. Need to find a model? Use the find method on this repository class that just calls the find method on a model. Great. You’ve now lost all the functionality and convenience of Eloquent less you write methods that completely re-implement each feature you need. I get design and architectural patterns are needed. But the repository pattern is never used for what it’s intended for and just means you now need to write more code for negative benefit. More on reddit.com
🌐 r/laravel
35
21
June 29, 2024
Proper implementation and befits of the Repository design pattern
Works great until you work with relationships or want to return a query builder object. I’ve yet to see an example of active-record repository pattern work in any non-trivial scenario. More on reddit.com
🌐 r/laravel
50
28
October 25, 2022
🌐
ASPER BROTHERS
asperbrothers.com › home › product development › laravel repository pattern – php design pattern
Laravel Repository Pattern – PHP Design Pattern | ASPER BROTHERS
September 10, 2022 - A model should be an object that represents a given table/document/object or any other type in our data structure, and this should be its sole responsibility. Therefore, to keep your Laravel code clean and safe, it is worth using repositories to separate the responsibility for which the model should never be responsible. The use of the PHP Repository Pattern has many benefits.
🌐
DEV Community
dev.to › blamsa0mine › structuring-a-laravel-project-with-the-repository-pattern-and-services-11pm
Structuring a Laravel Project with the Repository Pattern and Services 🚀 - DEV Community
November 21, 2024 - This article explores these concepts with practical examples to help you build a clean, testable, and maintainable Laravel project. The Repository Pattern provides an abstraction layer between the database and the business logic of your application.
🌐
OneUptime
oneuptime.com › home › blog › how to implement repository pattern in laravel
How to Implement Repository Pattern in Laravel
February 3, 2026 - The repository pattern makes testing straightforward. You can mock the interface and test your controllers in isolation, without touching the database. <?php namespace Tests\Feature; use Tests\TestCase; use App\Models\User; use App\Repositories\Contracts\UserRepositoryInterface; use Mockery; class UserControllerTest extends TestCase { /** * Test listing users returns paginated results.
🌐
ITNEXT
itnext.io › repository-design-pattern-done-right-in-laravel-d177b5fa75d4
Repository design pattern done right in Laravel | by Daan | ITNEXT
May 20, 2019 - The repository design pattern allows you to use objects without having to know how these objects are persisted. Essentially it is an abstraction of the data layer. This means that your business logic doesn’t need to know how data is retrieved ...
🌐
DEV Community
dev.to › victoor › repository-pattern-in-laravel-it-s-worth-3mn4
Repository Pattern in Laravel, it's worth? - DEV Community
September 26, 2023 - In Laravel we have Eloquent ORM and it is based on the Active Record pattern. Otherwise, Doctrine, from Symfony, is based on the repository pattern. In the active record pattern, each model corresponds to a table in our database and this model ...
Find elsewhere
🌐
DEV Community
dev.to › kasenda › use-repository-pattern-with-laravel-e8h
Use Repository Pattern with Laravel - DEV Community
December 11, 2022 - Modern PHP frameworks, such as Laravel and Symfony, interact with databases via Object-relational mappers (ORMs); Symfony uses Doctrine as its default ORM and Laravel uses Eloquent. Both take different approaches in how database interaction works. With Eloquent, Models are generated for each database table, forming the basis of interaction. Doctrine, however, uses the Repository pattern where each Entity has a corresponding repository containing helper functions to interact with the database.
🌐
Reddit
reddit.com › r/laravel › is using the repository pattern best practise?
r/laravel on Reddit: Is using the repository pattern best practise?
January 29, 2023 -

Is using the repository pattern best practise?

What's the size, scope, experience, need for performance/scaling etc. required to determine the approach/pattern for development to avoid code smell?

Repositories are common & I haven't seen a convincing alternative. I have read about Onion architecture, which is basically the repository pattern with a service layer between the repository & controller. For developers using PHP/Laravel, Whats you take and experience on this?

🌐
Kongulov
kongulov.dev › blog › repository-pattern-in-laravel-php-design-pattern
Repository Pattern in Laravel - PHP Design Pattern | Kongulov.dev
September 26, 2022 - A Repository is a centralized component that contains logic for accessing data sources. Implementing the Repository Pattern using an interface allows for reduced dependencies between classes, centralizing data access logic for easier maintenance, ...
🌐
Web Dev Etc
webdevetc.com › blog › the-repository-pattern-in-php-and-laravel
The Repository Pattern in PHP (and Laravel) - Web dev etc - my software development blog
A big advantage of using a framework such as Laravel is that you get so many features built into the core system. One of those is being able to automatically injecting classes via class hinting. Let's make some changes to the above code. To begin with, let's make an interface for the repository... <?php interface PostsRepoInterface { function postsInCategory(); }
🌐
Medium
tallstackdev.medium.com › introduction-to-the-repository-pattern-in-laravel-c025eb1cc7fd
Introduction to the Repository Pattern in Laravel | by Manish Kumar, Owner @Pixospace | Medium
September 2, 2024 - The Repository Pattern introduces a simpler way. Instead of going directly to the database, your application talks to a repository. The repository knows how to talk to the database. ... 12 yrs as a PHP dev, 7 in Laravel.
Top answer
1 of 3
19

You are over thinking, repository is just a link/bridge between your controller and model and hence controller uses repository class instead of the model directly and in that repository you may declare your methods using the model from there, for example:

<?php namespace GD\Repositories\Category;

interface CategoryInterFace{

    public function all();

    public function getCategoriesWith($with);

    public function find($id);
}

Now implement the interface in the repository class:

<?php namespace GD\Repositories\Category;

use \EloquentCategory as Cat; // the model
class CategoryRepository implements CategoryInterFace {
    public function all()
    {
        return Cat::all();
    }

    public function getCategoriesWith($with)
    {
        return Cat::with($with)->get();
    }

    public function find($id)
    {
        return Cat::find($id):
    }
}

To use it in your controller:

<?php

use GD\Repositories\Category\CategoryInterFace;

class CategoryController extends BaseController {

    public function __construct(CategoryInterFace $category)
    {
        $this->cat = $category;
    }

    public function getCatWith()
    {
        $catsProd = $this->cat->getCategoriesWith('products');
        return $catsProd;
    }

    // use any method from your category
    public function getAll()
    {
        $categories = $this->cat->all();

        return View::make('category.index', compact('categories'));
    }

}

Note: Omitted the IoC binding of the repository because this is not your problem and you know that.

Update: I've written an article here: LARAVEL – USING REPOSITORY PATTERN.

2 of 3
1

There is a really easy way to do this and it is explored in depth in this link

http://heera.it/laravel-repository-pattern#.U6XhR1cn-f4

I was looking for the exact solution and it is working well so far

so the idea for you would be to declare this in your repository code

public function __construct(\Category $category)
{
    $this->category = $category;
} 
public function getAllUsers()
{
    return $this->category->all();
}

public function __call($method, $args)
{
    return call_user_func_array([$this->category, $method], $args);
}

forcing the Model to be called when some functions are missing

🌐
Medium
medium.com › @shaunthornburgh › mastering-the-repository-design-pattern-in-laravel-67ed3805addd
Mastering the Repository Design Pattern in Laravel | by Shaun Thornburgh | Medium
September 1, 2023 - The Repository Design Pattern is a powerful tool that can significantly improve the structure and maintainability of your Laravel applications. By isolating the data access logic, you achieve code reusability, testability, and flexibility.
🌐
DEV Community
dev.to › carlomigueldy › getting-started-with-repository-pattern-in-laravel-using-inheritance-and-dependency-injection-2ohe
Getting Started with Repository Pattern in Laravel using Inheritance and Dependency Injection - DEV Community
March 28, 2021 - Go to the official docs for reference ...tion-via-composer · Create a directory inside the app and name it as Repository and inside it create another directory Eloquent then create a file named BaseRepository.php inside Eloquent directory ...
🌐
GitHub
github.com › imgrasooldev › repository-pattern-in-laravel
GitHub - imgrasooldev/repository-pattern-in-laravel: Repository Pattern is a software design pattern commonly used in object-oriented programming to separate the logic that retrieves and stores data from the rest of the application. It provides a way to abstract and encapsulate data access operations, making the code more modular, maintainable, and testable.
Overall, the Repository Pattern improves code organization, flexibility, and maintainability by abstracting data access operations and promoting modular design in software applications.
Starred by 6 users
Forked by 2 users
Languages   PHP 79.1% | Blade 20.7% | JavaScript 0.2% | PHP 79.1% | Blade 20.7% | JavaScript 0.2%
🌐
Laravel Daily
laraveldaily.com › lesson › design-patterns › repository-pattern
10 - Repository Pattern: Why I Don't Recommend It | Laravel Daily
As I understand it the purpose of a repository is to provide a data access layer between the business logic and the database (models), so (taking a as an example Orders, and Order lines which would be separate models) you might have a single Order repository to handle as an integrated whole the access to existing, and creation of new, orders with their associated order lines, ensuring for example, that creation of an Order has insertion of an order record and associated order lines as part of an atomic transaction, and that the created Order is a valid one (e.g.
🌐
DEV Community
dev.to › asperbrothers › laravel-repository-pattern-how-to-use-why-it-matters-1g9d
Laravel Repository Pattern - DEV Community
April 28, 2020 - The main idea to use Repository Pattern in a Laravel application is to create a bridge between models and controllers. In other words, to decouple the hard dependencies of models from the controllers.
🌐
Faun
faun.pub › how-to-use-the-repository-pattern-in-laravel-clean-scalable-code-example-a66b9cdf8fc8
How to Use the Repository Pattern in Laravel (Clean & Scalable Code Example) | by Tzedek | FAUN.dev() 🐾
July 30, 2025 - The Repository Pattern in Laravel is a design pattern that separates your application’s business logic from data access logic. ... Your controller doesn’t talk directly to Eloquent models — it talks to a repository interface instead. ... Let’s say you’re building an Order module. Here’s how your folder structure could look: app/ ├── Modules/ │ └── Order/ │ ├── Models/ │ │ └── Order.php ...