【问题标题】:Check a column is empty array or not in Laravel在 Laravel 中检查一列是否为空数组
【发布时间】:2020-06-24 06:34:33
【问题描述】:

我有一个 json 列,默认设置为 null,并在模型中转换为数组。 我用过

->where('column_name', '\[\]')->get();

它返回空集合。

我的问题是,如果我必须检查一列是否为空数组,在什么条件下我会做什么?

【问题讨论】:

  • 它会给你空集合,因为你的column_name 没有任何空数据。如果它有数组,则使用whereIn 而不是where

标签: laravel laravel-5


【解决方案1】:

感谢this answer

where('column_name',DB::raw("json_array()"))->get();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-04
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 2015-06-14
    • 2012-09-10
    • 2017-09-13
    • 2013-12-23
    相关资源
    最近更新 更多