I think I know what you're talking about, but not exactly. Could you please elaborate a little bit further with more examples?
I'm worried about interacting directly with Models - as Repositories are supposed to extract the DB layer from Controllers
Say I have:
class User extends Eloquent {
public $name;
public $email;
//...
public function roles() {
// return array of roles
}
public function addRole($role) {
// add a new role
}
public function posts() {
// return array of posts
}
}
The addRole()
and roles()
function interacts with another Eloquent class to create a record.
But now I want to migrate the Users and Roles to MongoDB. In theory the code contained within the User model could change drastically and cause a few bugs. If I have bind the model to an interface it at least assures the right functions are available.
If I've got concrete functionality connected to the User like addRole()
- should that go through a Repository or separate Application Service?
Should I also be worried about exposing 'getters'? The call $user->get('email')
could change when updating schema - what's the best practice to defend against that?
Another example, say I'm updating a field the code behind it could be different if I'm using NoSQL vs MySQL so should I worry about exposing methods through the Model and opt for updating in the repository instead?
ie: $user->set('name', 'Adam')
or $user_repository->update($id, ['name' => 'Adam']);
Right now the repository would call the $user->set()
method in a roundabout way but there is some protection there.
Sign in to participate in this thread!