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

Enea74's avatar

leftJoin query wraps string into backticks

I'm facing an odd error when using a leftJoin query.

$status = 'active';
$active_ids = \App\User::leftJoin('user_profiles', function($join) use ($status) {
                $join->on('user_profiles.user_id', '=', 'users.id')
                    ->on('user_profiles.status', '=', $status);
            })
            ->where('type', 'client')
            ->get();

I get the error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'active' in 'on clause' (SQL: select * from `users` left join `user_profiles` on `user_profiles`.`user_id` = `users`.`id` and `user_profiles`.`status` = `active` where `type` = client and `users`.`deleted_at` is null)

It seems that the string 'active' is automatically wrapped into backticks, thus MySQL is looking for a column with that name.

I couldn't find a solution, have you got a clue?

0 likes
2 replies

Please or to participate in this conversation.