2017-08-07 24 views
2

嗨如何檢查雄辯多態關係已經存在?如何檢查Eloequent多態的關係?

例如,我要防止在附件表中獲取存儲與同upload_id,attachable_id和attachable_type數據(參見高亮)

我所嘗試,但並沒有得到相關的正確計數存在:

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

enter image description here

回答

2

您只需查詢該upload_id相關附件:

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

感謝它的工作爲什麼我不能想到使用這個基本檢查:( – cyberfly