关联时想对关联表数据筛选时:
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();)
轉載:https://laravel-china.org/articles/7171/laravel-learning-records-orm-with-usage-model-association