1

Всем добрый вечер. Помогите пож, как мне написать нижеследующий запрос через Eloquent для Laravel. Столько гуглил не нашел решение, заранее спасибо!

select * from table_1 where (id in (select id_1 from table_2 where status = "success"))

1 ответ 1

0

Решение нашёл. Связываем таблицы.

Для первой таблицы (Модель) пишем:

public function table_1()
{
    return $this->belongsTo('Vendor\Project\Models\Models1', 'id', 'table_1_column');
}

Для второй таблицы (Модель) пишем:

public function table_2()
{
    return $this->hasOne('Vendor\Project\Models\Models2');
}

Далее в коде пишем:

$var = Models1::whereHas('data', function ($query) {
     $query->where('status', '=', 'success');
})->get();

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.