filter - Laravel 5.2 Select Where Has Related Count Data -
i have table called 'templates' , 'details' has relation templates has many details @ model.
i create list template table filter number or detail, when input 5 filter box, table show templates has 5 details.
how this?
this table structure :
templates
id | name | width | heigh
1 | a-5 | 112 | 100
2 | a-4 | 225 | 200
details
template_id | x | y
1 | 10 | 10
1 | 20 | 10
2 | 10 | 10
2 | 20 | 10
$templates = template::wherehas( 'details', function( $detail ) { $detail->selectraw( 'count(id) aduh' )->whereraw( 'count(id) = 100' )->groupby( 'id' ); } );
i think should work:
$templates = template::has('details', '=', 5)->get();
this return templates has 5 details.
Comments
Post a Comment