Open nenadmilosavljevic opened 6 years ago
You can use php's $_SESSION
variable for that.
->where(["language" => isset($_SESSION["user"]["language"]) ? $_SESSION["user"]["language"] : "en"])
@nenadmilosavljevic You can add more query conditions on your relations dynamically when calling them too, i.e.:
$page->translations->where(['language' => $user->lang]);
You can then put this in to a helper function or something (anything you want really):
function getPageTranslationForUser(Page $page, User $user) {
return $page->translations->where(['language' => $user->lang]);
}
Does this mean that if I want to get all pages for specific language I have to querry db for each page? What is $page exactly?
$page doesn't matter - it was just an example of getting page content specific to that user, so both the page and user are required. That can be literally any entity.
Hello, I know that I can filter related entities using this:
Id' like to do something like ->where(["userId" => $userId) but userId is read dinamically each time.