laravel - laravel 背包只显示不禁用元素
问题描述
我有一个表雇主,我可以在其中禁用单行。因此,当用户加载页面时,我只想显示未禁用的雇主,但我还希望有一个仅显示禁用用户的按钮。所以我在我的设置中使用
$this->crud->addClause("is_disable",true)
这很好用。问题是当用户点击禁用过滤器时,我有一个错误,因为我启用了过滤器 addClause("is_disable",true) 但现在我想要 addClause("is_disable",false)...当用户点击禁用按钮过滤器我必须删除子句 addClause("is_disable",true) 但我不知道该怎么做。是其他路径吗?
解决方案
您可以使用第四个参数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);
});
推荐阅读
- gitlab - 升级到 14.12 后无法访问 gitlab web UI
- angular - 角。将一个兄弟组件的选择器传递给另一个
- regex - Visual Studio 使用正则表达式在脚本标记之间查找文本
- flutter - 在 Flutter 中使用自定义包
- vhd - VHD 为什么根据我是使用 gwi win32_diskdrive 还是使用磁盘映像工具得到不同的扇区计数结果?
- java - 如何在不使用片段的情况下使用 Activity 制作 TabLayout?有可能吗?如果可能的话,我怎么能做到这一点?
- swagger - 用于主体模式的 swagger 微服务集成
- python - 在指定位置将图像插入 pdf
- arrays - Angular - 从数组缓冲区获取字节数组
- python - 从两个目录中获取输入