Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aperezmi's avatar

Help using join() with previous query

Hello:

I have doubts about using the join() function of a Model when a table is the result of a previous query.

I have a previous query which is in fact the result of joining two tables

$query = Model1::join('table2','table1.column1','=','table2.column1');

What I want to do is joining this query with a table represented by an Eloquent model, something like:

ModelA::join($query,'tableA.column1', '=', $query->columnIwant);

Is there any way to achieve this or should I create a temporary table for that purpose?

Thank you.

0 likes
1 reply

Please or to participate in this conversation.