如果我有类似以下的内容,我该如何添加左连接到“with(new Model)”部分?Laravel Eloquent left join in where where查询
Model::whereIn('name', function ($query) use ($link) {
$query->select('name')
->from(with(new Model)->getTable()) // would like to do a leftJoin here
->where('link', $link);
})->get();
我已经试过
Model::whereIn('name', function ($query) use ($link) {
$query->select('name')
->from(with(new Model)->leftJoin('tableZ', Model.col1, '=', tableZ.col1)->getTable())
->where('link', $link);
})->get();
我也试过:
Model::whereIn('name', function ($query) use ($link) {
$query->select('name')
->from(with(new Model)->getTable())
->leftJoin('tableZ', Model.col1, '=', tableZ.col1)
->where('link', $link);
})->get();
不完全知道我应该如何去这样做。
也许创建所需的原始SQL并发布。安装[debugbar](https://github.com/barryvdh/laravel-debugbar)并调试你想要的SQL查询。玩的开心! – Kyslik
该调试栏看起来非常漂亮。我会检查出来的。 – rotaercz
它应该首先安装...干杯! – Kyslik