在我的 Statamic 资产蓝图中,我有一个
users
字段,我只想将其限制为摄影师。我所有的摄影师用户都被放置在用户组photographers
中,根据Statamic文档,我可以使用查询范围来过滤这些用户。
例如,这是一位摄影师:
name: 'Dave Johnson'
groups:
- photographers
id: 1231u239021313-3218931230123-321893
这是一个假设的查询范围:
<?php
namespace App\Scopes;
use Statamic\Query\Scopes\Scope;
class PhotographerScope extends Scope
{
/**
* Apply the scope.
*
* @param \Statamic\Query\Builder $query
* @param array $values
* @return void
*/
public function apply($query, $values)
{
// $query->whereJsonContains('groups', 'photographers');
// some sort of query here to only select photographers?
}
}
如何完成此查询以仅选择在
photographer
数组中具有 groups
值的用户?
显然,可以检查如下子字段:
<?php
namespace App\Scopes;
use Statamic\Query\Scopes\Scope;
class PhotographerScope extends Scope
{
/**
* Apply the scope.
*
* @param \Statamic\Query\Builder $query
* @param array $values
* @return void
*/
public function apply($query, $values)
{
$query->where('groups->photographers', true);
}
}
给我的消息。希望这对某人有帮助。