[Laravel] - | Learning records | ORM 模型关联 with () 用法
关联时想对关联表数据筛选时:
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 协议》,转载必须注明作者和本文链接
推荐文章: