我正在尝试通过纯枚举字段在数据库中执行搜索:
enum Enum1 {
case Case1;
}
Model::query()->where('enum1', Enum1::Case1)->first()
并且它不起作用,导致错误 Error Object of class Enum1 Could not be conversion to string.
当我通过支持的枚举进行搜索时,它有效:
enum Enum2: int {
case Case1 = 1;
}
Model::query()->where('enum2', Enum2::Case1)->first()
在 Model->casts 中,为 Enum1 和 Enum2 提供值。
我知道,我可以通过 Enum1::Case1->name 进行搜索,但这不是我要找的。如果可能的话,我想安排合适的演员。
处理这个问题最简单/正确的方法是什么?
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号