从la中的另一个表中选择列中的表中选择

时间:2015-03-21 12:30:20

标签: laravel eloquent

我有以下查询

SELECT * FROM answers where (id_question in (select id from questions where id_quiz = 3)) 

我需要知道如何用laravel eloquent

来写它

2 个答案:

答案 0 :(得分:2)

Answer::whereIn('id_question', function($query) {
    $query->table('questions')->where('id_quiz', 3)
})->get();

答案 1 :(得分:2)

table方法不再有效,请改用from方法

Answer::whereIn('id_question', function($query) {
    $query->from('questions')->where('id_quiz', 3)
})->get();