I want to filter evaluations with a query scope, but in my model I have a fillable which is an array and it is from there that I want to filter

我的模型中有一个属性是一个目标(数组),其中为每个评估保存分配给该评估的角色 .

protected $fillable = [
    'id',
    'title',
    'description',
    'editable_before',
    'available_start',
    'available_end',
    'client_id',
    'meta',
];

protected $casts = [
    'meta' => 'array',
];

这是一个测试向您展示的评估

"id": 90,
"title": "inquiry Irvin Giovanni",
"description": "description encuesta irvin",
"instructions": null,
"editable_before": null,
"available_start": "2017-11-13 00:00:00",
"available_end": "2017-11-13 00:00:00",
"client_id": 9,
"meta": {
  "userTypes": [
      {
        "role": "COACH",
        "level": "KIN"
      },
      {
        "role": "ADMIN",
        "level": "SEC"
      },
      {
        "role": "PROF",
        "level": "SEC"
      }
    ]
}

我想根据查询范围接收的角色类型过滤评估

理念:

public function scopeRole($query, $role)
{
    return $query->where('meta.userTypes', '=', $role);
}

the idea is that in the parameter of the query scope function could pass "ADMIN", "PROF", "COACH" and I return the evaluations that have a certain parameter