Level 4
try this
DB::table('project_user')->whereColumn([['project_id', '=', '1'], ['user_id', '=', '1']])->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the table:
CREATE TABLE `project_user` (
`project_id` int(10) unsigned NOT NULL,
`user_id` int(10) unsigned NOT NULL,
`role_id` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
KEY `project_user_project_id_index` (`project_id`),
KEY `project_user_user_id_index` (`user_id`),
CONSTRAINT `project_user_project_id_foreign` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`),
CONSTRAINT `project_user_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
which includes the record
1 1 3 2018-01-03 12:12:01 2018-01-03 12:12:01
and when I run with tinker the query
DB::table('project_user')->whereColumn([['project_id', '=', 1], ['user_id', '=', 1]])->get();
I get the error message
Illuminate\Database\QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column '1' in 'where clause' (SQL: select * from `project_user` where (`project_id` = `1` and `user_id` = `1`))'
Its reporting Column not found: 1054 Unknown column '1', ... but 1 is not a column title.
this should be solution why need whereColumn clause it work with where clause
DB::table('project_user')->where([['project_id', '=', 1], ['user_id', '=', 1]])->get();
Please or to participate in this conversation.