【问题标题】:get the null,blank value from the table从表中获取空值、空白值
【发布时间】:2020-11-07 17:33:26
【问题描述】:

我想从表中的“category_type”字段中获取 [null]、空白或空格的值 我想获取 category_type 中的 [null]、blank、'Uncategorized' 或空格。 现在我只能获取空值。也需要获取空值。如何在 laravel 查询中的 postgres db 中获取空值字段。

我已经创建了变量$category=[]

if(in_array('Uncategorized',$category)){
          $category[]='';    
        $category[]='-';                  
        $category[]=' ';                  
        $category[]=null;                 
     }
 $table=DB::('category')->where('category.category_type',$category)->pluck('name')->toArray();

【问题讨论】:

标签: php laravel postgresql laravel-5


【解决方案1】:

您可以添加whereNull() 来检查空值并添加whereIn 来检查值数组:

if(in_array('Uncategorized',$category)){
        $category[]='';    
        $category[]='-';                  
        $category[]=' ';                                   
}

$table = DB::('category')->whereNull('category.category_type')
           ->whereIn('category.category_type', $category)
           ->pluck('name')
           ->toArray();

$table = DB::('category')->whereNull('category.category_type')
           ->orWhereIn('category.category_type', $category)
           ->pluck('name')
           ->toArray();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    • 2020-03-11
    • 1970-01-01
    相关资源
    最近更新 更多