首页 > 解决方案 > laravel 背包只显示不禁用元素

问题描述

我有一个表雇主,我可以在其中禁用单行。因此,当用户加载页面时,我只想显示未禁用的雇主,但我还希望有一个仅显示禁用用户的按钮。所以我在我的设置中使用

$this->crud->addClause("is_disable",true)

这很好用。问题是当用户点击禁用过滤器时,我有一个错误,因为我启用了过滤器 addClause("is_disable",true) 但现在我想要 addClause("is_disable",false)...当用户点击禁用按钮过滤器我必须删除子句 addClause("is_disable",true) 但我不知道该怎么做。是其他路径吗?

标签: laravellaravel-backpack

解决方案


您可以使用第四个参数addFilter()- 它是回退逻辑。当过滤器未激活时,将调用该闭包。我认为这正是您正在寻找的:

$this->crud->addFilter([ // add a "simple" filter called Disabled
  'type'  => 'simple',
  'name'  => 'disabled',
  'label' => 'Disabled',
],
false, // the simple filter has no values above
function () { // if the filter is active
    // do nothing; no filtering is actually needed
},
function () { // if the filter is NOT active
    $this->crud->addClause('is_disable', true);
});

推荐阅读