Ad

How To Use "hardcoded" Scopes In Backend Lists

- 1 answer

I'd like to display a list of records in 2 separate tabs. For example, lets take invoices. In the first tab, there should be records with status="paid" and in the second tab with status="new"

I know I can create the tabs in the controllers index view and use different list definitions but I cant figure out how to force a scope on a list definition.

The same thing can be done in the realation config file by using the conditions options

Ad

Answer

You can override the listExtendQuery function in the controller, about like this

public $listConfig = ['status_paid' => 'config_paid_list.yaml', 'status_new' => 'config_new_list.yaml'];

...

public function listExtendQuery($query, $definition = null) {
    if ($definition == 'status_paid') {
        $query->where('status', 'paid');
    } elseif ($definition == 'status_new') {
        $query->where('status', 'new');
    }
}
Ad
source: stackoverflow.com
Ad