Skip to content
Advertisement

Laravel pass parameter to its distant relationship (translate children)

I have categories with id, parent_id, slug , pivot table category_language which columns are id,category_id,language_id,value As you can see I can translate parent category, but can’t send desired $lang_id to children translations, so each children having all translations here is what I get:

JavaScript

Controller:

JavaScript

Model

JavaScript

Advertisement

Answer

Dry7 answer was close to the one I’ve implemented later, so I upvoted him. Finally in model I’ve added: ...->where('language_id',helper_SetCorrectLangIdForQuery());

and function helper_SetCorrectLangIdForQuery is using global helper of Laravel request()->lang . If lang=enz, than it takes default language from another helper.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement