Answer the question
In order to leave comments, you need to log in
Selecting products from categories that have a similar slug, what subquery is needed in join?
Purpose: to select a category name by slug for localization. For example, a user has requested a product with the Phone category and the product from this category will be returned to him, however, some products have been added to the Phone category , that is, there are 2 categories. The structure in the database is:
['lang' => 'en', 'name' => 'Phone', 'slug' => 'phone-en'],
['lang' => 'ru', 'name'=>'Телефон', 'slug' => 'phone-ru'],
->join('categories', function ($join) use ($localLang) {
$join->on('products.categorie_id', '=', 'categories.id')
->where('categories.slug', 'ILIKE', '%?????????%');
})
->where('categories.slug', 'ILIKE', '%' . $localLang . '%'); // ru
->where('categories.slug', 'ILIKE', '%' . $categoryOfCurrentProduct . '%'); // вместо ru будет phone
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question