2016-07-20 20 views
0

Wie kann ich die folgende Abfrage in Eloquent tun?Inverse Beziehung Lookups in Laravel

SELECT count(*) as total, age 
FROM user 
JOIN role ON user.role_id = role.id 
WHERE role.name = 'maintenance' 
GROUP BY age 

(wo 'Alter' ist auf user)

Antwort

1

Ungeprüfte:

$total = App\User::whereHas('roles', function ($query) { 
    $query->where('name', 'maintenance'); 
})->groupBy('age')->count();