laravel满足列的有效载荷数据的地方

时间:2020-08-19 07:24:23

标签: php laravel

我有一个名为MyModel的模型。其中一列称为“有效负载”,该列存储json数据。因此,数据示例如下:

import java.util.*;

public class HW8Problem1{
   public static void main(String[] args) {

      Scanner input = new Scanner(System.in);

      System.out.print("Enter a letter: ");

      String letter = input.nextLine();
//the below is the start of  IF expression, put it in one line code
      if (letter.toUpperCase().charAt(0)== 'A'||letter.toUpperCase().charAt(0)== 'E'||letter.toUpperCase().charAt(0)== 'O'||letter.toUpperCase().charAt(0)== 'i'||letter.toUpperCase().charAt(0)== 'U' ){ //End of IF expression until here, in 1 line
            System.out.println("is a vowel");
      }else{
        System.out.println(" is a consonant"); 
      }
      
   
   }

 }

我的意图是像这样获取表集合:

{
    "ProductCode": {
        "id": "1",
        "name": "My Service",
    }
    
}

我要满足的条件是返回有效载荷列的 productCode id 的数据

请问我该如何编写查询?

1 个答案:

答案 0 :(得分:1)

尝试做

$myCollection = MyModel::whereJsonContains('payload', ['productCode' => ['id' => 1]])->get();