Laravel 9枚举条件
我创建一个枚举,我添加了一个条件:
<?php
declare(strict_types=1);
namespace App\Enums;
use App\Models\collections;
enum ServiceColections : string {
case POS = (isset(collections::first()))? 'POS' : '';
}
如果数据库中有项目(表集合),则条件是以下条件,因此请创建Case POS,但是如果它们不存在,则不会创建。
目前,我遇到此错误:枚举案例值必须是编译时间评估
为什么它不起作用?
I'm create one enum, and I added one condition:
<?php
declare(strict_types=1);
namespace App\Enums;
use App\Models\collections;
enum ServiceColections : string {
case POS = (isset(collections::first()))? 'POS' : '';
}
the condition is the following if there are items in the database(table collections), so create case POS, but if they don't exist don't create.
currently I'm having this error: Enum case value must be compile-time evaluatable
why it dont work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如其自我所说的错误时,这在编译时行不通。
我们可以做的是,添加枚举方法:
可以像这样使用的方法:
As the error its self say, this will not work at the time of compiling.
What we can do is, add enum method:
Methods can be used like so: