gpt4 book ai didi

laravel - 如何检查 Eloquent 多态关系是否存在?

转载 作者:行者123 更新时间:2023-12-02 12:13:47 25 4
gpt4 key购买 nike

嗨,我如何检查 Eloquent 多态关系是否已经存在?

例如,我想阻止具有相同 upload_id、attachable_id 和 Attachable_type 的数据存储在附件表中(请参阅突出显示部分)

我尝试过但没有得到正确的关系计数:

//get count of attachment
$application->has('attachments')->count()

enter image description here

最佳答案

您只需查询该upload_id的相关附件即可:

$hasAttachments = $application->attachments()
->where('upload_id', $upload_id)
->count() > 0;

关于laravel - 如何检查 Eloquent 多态关系是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45548940/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com