Reputation: 1743
public function getGroupCategories() {
$group_categories = GroupCategory::with('groupCategoriesTranslation', function($query) {
$query->where('code', 'en');
});
return $group_categories;
}
Hello,
I want to write this query in eloquent :
SELECT * FROM group_categories AS gc INNER JOIN group_categories_translation AS gct ON gc.id = gct.group_category_id WHERE gct.code = 'en'
Laravel version is 5.3
Error :
mb_strpos() expects parameter 1 to be string, object given
It works when i use whereHas instead of with, but it returns only group_category.
Upvotes: 0
Views: 4234
Reputation: 820
You're using wrong syntax. Correct syntax for with() is:
public function getGroupCategories() {
$group_categories = GroupCategory::with(['groupCategoriesTranslation' => function($query){
$query->where('code', 'en');
}]);
return $group_categories;
}
Upvotes: 4