Reputation: 453
users Tabel
**id|name**
1|xx
users_meta Table
id | user_id | metaKey | metavalue
1 | 1 | city | kolkata
2 |2 |city | london
3 |8 |city |london
My moto is to return users belongs to city London.How can i achive this??
Upvotes: 0
Views: 319
Reputation: 15951
Lets say u have a relationship with Users and user_meta
Than simply
User::with(['userMeta' => function($query){
$query->where('metaKey', 'city')
$query->where('metavalue', 'london')
}]);
Hope this helps
Upvotes: 1
Reputation: 18187
You can query using whereHas
:
User::whereHas('users_meta', function ($query) {
$query->where('metavalue', 'london');
})->get();
Upvotes: 1