簡體   English   中英

我如何使用 whereHas 從 eloquent 中的相關 mophic 表中獲取數據

[英]How can i use whereHas to get data from related mophic table in eloquent

我正在使用 eloquent,任何幫助!

return House::whereHas('extendable', function($extendUnits) use($projectdeciphered){
    $extendUnits->where('project_id', $projectdeciphered);
});

您可以使用此處記錄的 whereHasMorph: https://laravel.com/docs/9.x/eloquent-relationships#querying-morph-to-relationships

House::whereHasMorph('extendable', [Extend::class, Unit::class], function($extendUnits) use($projectDeciphered){
    $extendUnits->where('project_id', $projectDeciphered);
});

希望這可以幫到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM