This is an example of “entity classes” using the domain model pattern. The classes are typically created to represent database tables, making their relationship to a RDBMS clear. We can introduce a mapper like Doctrine and/or Eloquent which is used in Laravel into the mix or create them by hand.
We start with a base class called.. Base and setup the initial getters / setters as well as two methods: a static method arrayToEntity and entityToArray. These allow us to convert an array to an instance of the entity class and back to a plain old array, or “hydrate” them.
Assuming we are building a class to handle Department data, the two sub-classes are
Departments.php
DepartmentsRepository.php