Add a scope to the config_list.yaml?

Hi,

I am wondering what would be the best way to do this.

I got these models : “Pool”, “Customer”, “Backend\Models\User”.

A Backend\Models\User has 1 (or many) Pool and inside a Pool, there is one (or many) Customer.

When I click to get the list of the customers, I need to only display the customers inside the pools that are linked to the current backend user.

I thought adding maybe a scope inside config_list.yaml but it’s not possible.

Any ideas ?

Thank you.

I ended up doing this in the controller for the model I needed to filter (based on the logged user) :

public function listExtendQuery($query, $definition = null) {
    $user = BackendAuth::getUser();
    $dealers = scopeAuthorizedDealers($query, $user);
    $query->whereIn('dealer_id', $dealers)->get();
}

In the documentation, I can find info about local scope and dynamic scope but nothing about global scope. I don’t know if it could be something good to get there… ?

Because with the solution above, you have to be careful to update and manage access in the update.htm (if somebody changes the recordId manually). You have to check that too.

1 Like

Laravel docs cover adding global scopes to a model: Eloquent: Getting Started - Laravel - The PHP Framework For Web Artisans

1 Like