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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -