Laravel 4.2生成这样的子查询

时间:2015-04-01 13:45:52

标签: laravel-4

我想以雄辩的方式做到这一点。

select * from `documents` where (`id` in (select `related_id` from
`common_data` where `meta_key` = 'meta_key_name' and `meta_value` =
'1') or `created_by` = '1')

感谢您的回答。

1 个答案:

答案 0 :(得分:1)

试试吧

$data = Document::where(function($query){
   $query->whereRaw(" id in (select `related_id` from `common_data` where `meta_key` = 'meta_key_name' and `meta_value` ='1')")
        ->orWhere('created_by',1);
})->get();