如何在后端列表中使用 "hardcoded" 范围
How to use "hardcoded" scopes in backend lists
我想在 2 个单独的选项卡中显示记录列表。
例如,让我们拿发票。在第一个选项卡中,应该有带有 status="paid"
的记录,在第二个选项卡中带有 status="new"
我知道我可以在控制器索引视图中创建选项卡并使用不同的列表定义,但我不知道如何在列表定义上强制范围。
通过使用 conditions
选项
,可以在 realation 配置文件中完成同样的事情
你可以重写controller中的listExtendQuery函数,大概像这样
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');
}
}
我想在 2 个单独的选项卡中显示记录列表。
例如,让我们拿发票。在第一个选项卡中,应该有带有 status="paid"
的记录,在第二个选项卡中带有 status="new"
我知道我可以在控制器索引视图中创建选项卡并使用不同的列表定义,但我不知道如何在列表定义上强制范围。
通过使用 conditions
选项
你可以重写controller中的listExtendQuery函数,大概像这样
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');
}
}