在不同的JSON对象键中获取Join查询结果

时间:2018-07-08 05:40:02

标签: json join laravel-5.6

我在Laravel控制器中有一个类似下面的查询,我正在使用它进行API开发。

return $post
            ->comments()
            ->join('translationCHN', function ($join) {
                $join->on('comment.word_id', '=', 'translationCHN.word_id');
                $join->on('comment.sentence_id', '=', 'translationCHN.sentence_id');
            })
            ->get();

我正在获取JSON格式的输出。从这个查询中,我想得到不同的JSON对象密钥translationCHN的结果。

那怎么办?

UPDATE

我得到如下输出

{
    "id": 1,
    "word_id": 1,
    "verse_id": 1,
    "arabic": "بِسْمِ اللَّهِ الرَّحْمٰنِ الرَّحِيمِ",
    "bayan": "dfgsdfgdfgfdsg",
    "mkhan": "fgdgdgdsfg",
    "kathir": "dfgdgfdfds",
    "taisir": "dfgfdsgdsfgs",
    "mujib": "dfsfgdsfgdsgfds",
    "indo_pak": "بِسۡمِ اللّٰہِ الرَّحۡمٰنِ الرَّحِیۡمِ ﴿۱﴾",
    "kasir": "dfgdsgdsgsdfgsdf",
    "fmazid": "khkhjkhhhhkgkxfxdx",
}

我想得到如下输出

{
    "id": 1,
    "word_id": 1,
    "verse_id": 1,
    "arabic": "بِسْمِ اللَّهِ الرَّحْمٰنِ الرَّحِيمِ",
    "bayan": "dfgsdfgdfgfdsg",
    "translationCHN": {
        "mkhan": "fgdgdgdsfg",
        "kathir": "dfgdgfdfds",
        "taisir": "dfgfdsgdsfgs",
        "mujib": "dfsfgdsfgdsgfds",
        "indo_pak": "بِسۡمِ اللّٰہِ الرَّحۡمٰنِ الرَّحِیۡمِ ﴿۱﴾",
        "kasir": "dfgdsgdsgsdfgsdf",
        "fmazid": "khkhjkhhhhkgkxfxdx",
    }
}

0 个答案:

没有答案