Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hernandev's avatar

Models and Interfaces on 4.3

Hi, it's little early to get some definitive on 4.3 best practices, but how would you set models interfaces and where did you put them?

on 4.2 and early, i normaly did something like

Me\Project -> Main Namespace

Me\Project\Models -> Holds Interfaces for Models

Me\Project\Models\Eloquent -> Holds models extending Eloquent Model

and them i bind them the Interfaces with the Eloquent models, making it little more easy to change to another ORM / DBAL implementation if needed.

On 4.3, how would you do something similar to allow better code imteroperatibily.

Thank you so much!

0 likes
3 replies
uxweb's avatar

I think just a matter of create the directories that match your application "domain" or "business".

For example, for managing the application users i should create a users directory to store and organize the code related to this part of the domain, there i'll put my model, repository, commands and other components needed.

xingfucoder's avatar

Hi, if you need to manage some business domain, I would create something as follow:

app
  Domain
      BusinessEntity1
               Entities
                    BusinessEntity1
                    ...
               Factories
                    BusinessEntity1Factory
               Repositories
                    IBusinessEntity1Repository
               ...
     BusinessEntity2
               Entities
                    BusinessEntity2
                    ...
               Factories
                    BusinessEntity2Factory
               Repositories
                    IBusinessEntity2Repository
               ...
      BusinessEntityN

      DomainServices
               ...
   Infraestructure (To manage the storage / persist)
       Repositories
             DB
                 AbstractDBRepository
                 BusinessEntity1DBRepository
                 BusinessEntity2DBRepository

Hope it helps you.

1 like
hernandev's avatar

both sounds legit, thank you guys for your opinion

Please or to participate in this conversation.