nhayder
1 week ago

how to chain relationships with query builder

Posted 1 week 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)
    {

        if($id){

            $pageID = $id;

        }else{

            $id = 1;

        }

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

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

                    }],

                    'category.articles.editor',

                    'category.articles.poster',

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

                )

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

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

        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.