Proper Repository Pattern Design in PHP?

后端 未结 11 778
天涯浪人
天涯浪人 2020-11-29 14:22

Preface: I\'m attempting to use the repository pattern in an MVC architecture with relational databases.

I\'ve recently started learning TDD in PHP, and I\'

11条回答
  •  悲哀的现实
    2020-11-29 14:38

    I agree with @ryan1234 that you should pass around complete objects within the code and should use generic query methods to get those objects.

    Model::where(['attr1' => 'val1'])->get();
    

    For external/endpoint usage I really like the GraphQL method.

    POST /api/graphql
    {
        query: {
            Model(attr1: 'val1') {
                attr2
                attr3
            }
        }
    }
    

提交回复
热议问题