Level 75
Instead of
->on('user_profiles.status', '=', $status);
use
->where('user_profiles.status', $status);
With on you compare columns and not data.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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?
Instead of
->on('user_profiles.status', '=', $status);
use
->where('user_profiles.status', $status);
With on you compare columns and not data.
Please or to participate in this conversation.