【问题标题】:what is the use of '<>' in ->where('id', '<>', $id)->where('id', '<>', $id) 中的 '<>' 有什么用
【发布时间】:2021-01-19 15:46:13
【问题描述】:

我无法理解&lt;&gt;-&gt;where('id', '&lt;&gt;', $id) 中的用途

protected function getRelatedSlugs($slug, $id = 0){
    return Product::select('slug')
    ->where('slug', 'like', $slug.'%')
    ->where('id', '<>', $id)->get();
}

【问题讨论】:

标签: laravel eloquent


【解决方案1】:

the documentation:

第二个参数是一个操作符,可以是任何数据库支持的操作符

所以在你的数据库手册中查找。

你没有说你用的是什么数据库,那我们看看PostgreSQL 13

数据类型 数据类型 → 布尔值:不等于

所以它的意思是“id不等于$id的值。

换句话说,当你得到与当前相关的 slug 时,你不想返回列表中的当前那个。

【讨论】:

    猜你喜欢
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    相关资源
    最近更新 更多