10 months ago

how to chain relationships with query builder

Posted 10 months ago by nhayder

i'm trying to get editor and poster data for every article in single query, unfortunately i'm not getting these data on the final query.

this is my code

    public function widgets($id = null)


            $pageID = $id;


            $id = 1;


        $widgets = Widget::with(
                    ['category.articles' => function ($query) {

                        $query->where('language', 'en');




                    'buttons', 'content', 'content.linkedPage', 'content.linkedArticle'


            ->where('page_id', '=', $id)

            ->orderBy('sorting', 'asc')

        return $widgets;


After running the code i'm not returning the editors neither the poster data.

is there is a better way on how to this type of query.

any ideas ???

Please sign in or create an account to participate in this conversation.