Support the ongoing development of Laravel.io →
Database Eloquent Architecture
Last updated 2 years ago.
0

I think I know what you're talking about, but not exactly. Could you please elaborate a little bit further with more examples?

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Has anyone got any advice on this one for me?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.