[Laravel] - | Learning records | ORM 模型關聯 with () 用法

yangxiaopeipei發表於2017-12-20

關聯時想對關聯表資料篩選時:
MySQL查詢:

SELECT *  FROM A
LEFT JOIN B
ON A.B_id = B.id AND B.condition = $condition

ORM模型查詢使用with():

Model::with(['table_name' => function ($query) use ($condition) {
            $query->where( "condition", $condition)
                        }])->get();)
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章