-2

Is there a way to translate the following syntax to laravel query builder?

SELECT *
FROM table_1
INNER JOIN table_2 ON table_1.id = table_2.id
INNER JOIN table_3 ON
(CASE
      WHEN {some condition}
      THEN table_1.id
      ELSE table_2.id
END) = table_3.id;
Mark Adel
  • 223
  • 1
  • 10

1 Answers1

0

Your question is not specific enough but here is the closest answer to your question:

DB::table('table_1')
    ->join('table_2', 'table_1.id', '=', 'table_2.id')
    ->join('table_3', function ($join) {
        $join->on('table_3.id', '=', DB::raw('case when {some condition} then u table_1.id else table_2.id end'));
    })
    ->get();

Note: use models will save you time.

mwafi
  • 3,946
  • 8
  • 56
  • 83