Laravel 5.2选择具有相关计数数据的位置

Laravel 5.2选择具有相关计数数据的位置,laravel,filter,Laravel,Filter,我有一个名为“templates”和“details”的表,其中包含关系模板,在我的模型中有许多详细信息 我创建了一个带有筛选器编号或详细信息的列表模板表,当我在筛选器框中输入5时,该表仅显示具有5个详细信息的模板 如何做到这一点 这是我的表格结构: 模板 id |名称|宽度|高度 1 | A-5 | 112 | 100 2 | A-4 | 225 | 200 详细信息 模板id | x | y 1 | 10 | 10 $templates = Template::whereHas( 'deta

我有一个名为“templates”和“details”的表,其中包含关系模板,在我的模型中有许多详细信息

我创建了一个带有筛选器编号或详细信息的列表模板表,当我在筛选器框中输入5时,该表仅显示具有5个详细信息的模板

如何做到这一点

这是我的表格结构:

模板

id |名称|宽度|高度

1 | A-5 | 112 | 100

2 | A-4 | 225 | 200

详细信息

模板id | x | y

1 | 10 | 10

$templates = Template::whereHas( 'details', function( $detail ) {
    $detail->selectRaw( 'count(id) as aduh' )->whereRaw( 'count(id) = 100' )->groupBy( 'id' );
} );
1 | 20 | 10

$templates = Template::whereHas( 'details', function( $detail ) {
    $detail->selectRaw( 'count(id) as aduh' )->whereRaw( 'count(id) = 100' )->groupBy( 'id' );
} );
2 | 10 | 10

$templates = Template::whereHas( 'details', function( $detail ) {
    $detail->selectRaw( 'count(id) as aduh' )->whereRaw( 'count(id) = 100' )->groupBy( 'id' );
} );
2 | 20 | 10

$templates = Template::whereHas( 'details', function( $detail ) {
    $detail->selectRaw( 'count(id) as aduh' )->whereRaw( 'count(id) = 100' )->groupBy( 'id' );
} );

我认为这应该奏效:

$templates = Template::has('details', '=', 5)->get();

这将返回包含5个详细信息的所有模板。

我认为这应该可以:

$templates = Template::has('details', '=', 5)->get();
这将返回包含5个详细信息的所有模板。

详细信息是否在您的表中?你能添加你的表结构和你期望得到的结果吗?详细信息是你表中的一列吗?你能添加你的表结构和你期望得到的结果吗?