eloquent - 十月CMS范围不适用
问题描述
所以这里的场景是我试图在 OctoberCMS 中创建一个简单的范围,这将允许我使用构建器插件列表组件过滤查询。在我的模型中,我已将范围定义为:
public function scopeFirst($query)
{
return $query->where('practice_name',1);
}
这应该只是将查询限制为仅获取该值为 1 的记录。组件正在识别此范围并允许我从下拉列表中选择它,如我的 index.htm 文件所示:
[builderList]
modelClass = "vetadmin\Practicedetails\Models\Practicedetails"
scope = "scopeFirst"
displayColumn = "id"
noRecordsMessage = "No records found"
detailsPage = "-"
detailsUrlParameter = "id"
pageNumber = "{{ :page }}"
有没有人知道什么可能导致它不应用约束?目前 - 所有 - 正在返回记录。文档没有特别详细说明这一点,只是建议您需要在插件模型 php 文件中定义范围(正如我所做的那样)
https://octobercms.com/docs/database/model#query-scopes
是我指的文档。
谢谢。
解决方案
嗯,这对larval eloquent model
我已经测试了您的代码和范围
然后我才意识到scopeFirst
可以像这样应用于模态$modal->first()
<=this is issue its reserved method
据我所知first
[ref: https://laravel.com/docs/5.7/eloquent]是从collection/models
. [所以,你的范围被这样对待,最终什么也没做!]
因此,只需更改您的范围名称
scopeFirstPractice
等即可解决我们的问题。
并且通常使用
[builderList]
modelClass = "vetadmin\Practicedetails\Models\Practicedetails"
scope = "scopeFirstPractice"
它绝对应该有效。【我已经测试过了。]
如有任何疑问,请发表评论。
推荐阅读
- sql - 来自多个数据库记录的 SQL 视图
- c++ - 使用 Direct2D 在非客户区绘图
- google-drive-api - 如何获取个人资料信息谷歌照片库api
- python - ValueError:形状不匹配:形状相同
- sorting - 通过 Google 表格中的参数对海量数据进行排序
- xml - 需要通过 XSLT 将我的 XML 转换为另一个特定格式的 XML
- r - 将字符列转换为 lubridate 中的日期列
- json - 将列转移到 JSON 末尾的 JOLT 规范
- python - XGboost - 网格搜索无法正常工作
- javascript - 我如何订购 React 中的组件