acoustep/entrust-gui

Why don't use repository to fetch data?

Closed this issue · 1 comments

I wonder when you are using repositories, why here in UsersController you are fetching roles from database directly without using RoleRepository?

    public function create()
    {
        $user_class = $this->config->get('auth.providers.users.model');
        $user = new $user_class;

       // Why don't use RoleRepository
        $roles = $this->role->pluck('name', 'id');

        return view(
            'entrust-gui::users.create',
            compact(
                'user',
                'roles'
            )
        );
    }

Isn't better to use repositories anywhere we want to interact with our data resources, so when resources change (e.g: data stored in MYSQL database goes to NOSQL) we can easily make another implementation of repository interface and use it.

Hi @akoSalman ,

You make a good point, it's something I didn't think about at the time 🙂.

In the UsersController construct the role property is actually pulled from the config file.

So if you wanted to use a different database (or even make your own repository) as long as you implemented the pluck method on your own class then you would be able to do that.