【发布时间】:2019-03-28 22:52:30
【问题描述】:
我有一张牌桌冠军和一张牌桌用户。我也有相同的模型(冠军和用户)。
在一个锦标赛中,可能有一名主裁判、主秘书和裁判操作员。所有这些也是我的应用程序中的角色并存储在角色表中。
我创建了一个新的资源锦标赛,其中包含 3 个 belongsTo 字段。所有这些都可以搜索。
BelongsTo::make('Main judge', 'mainJudge', User::class)
->onFormsAndDetail()
->searchable(),
BelongsTo::make('Main secreatary', 'mainSecretary', User::class)
->onFormsAndDetail()
->searchable(),
BelongsTo::make('Judge operator', 'judgeOperator', User::class)
->onFormsAndDetail()
->searchable(),
在搜索过程中,我需要过滤查询,以便仅搜索具有相同角色的用户。
例如,在搜索主判断期间,我必须在查询中包含下一个过滤器
select *
from users u
join users_roles ur on u.id = ur.user_id
join roles r on ur.role_id = r.id
where r.alias = 'judge'
我在 app/Nova/Resource.php 中找到了一些方法,例如 relatableQuery,但是如果我有 3 个用户字段,如何在用户资源中使用它。
【问题讨论】:
标签: laravel-5 eloquent laravel-nova