Laravel 查询其中 col1 != col2

Laravel query where col1 != col2

我有 table 'items' 和 'col1'、'col2' 等列的数据库。 我需要 laravel ORM 的结果项。 条件:col1 != col2

的所有项目
where col1 != col2

您可以使用 Laravel whereColumn。它用于比较两列。您可以在此处查看文档 https://laravel.com/docs/8.x/queries

DB::table('table_name')->whereColumn('col1', '<>', 'col2')->get();