Redadublex
Redadublex

Reputation: 129

Select from table where column in select from another table in laravel

I have the following query

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

I need to know how to write it in laravel eloquent

Upvotes: 1

Views: 2043

Answers (2)

Tom
Tom

Reputation: 21

table method is not valid any more, use from method instead

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

Upvotes: 2

Limon Monte
Limon Monte

Reputation: 54389

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

Upvotes: 2

Related Questions