1 year ago

Laravel eager loading doesn't work while using view::composer() method

Posted 1 year ago by hsntngr

I'm trying to get some of current post for sidebar. So I create a composer method inside of [email protected] method.

I'm able to get products and also see to media relation in relations segments. But it seems empty. (But all products have 3 image minimum )

\View::composer("frontend._partials._sidebar", function ($view) {
            $new_products = Product::select("title", "slug")
                ->orderBy("id", "desc")

            $view->with("new_products", $new_products);

#relations: array:1 [▼ "media" => Collection {#930 ▼ #items: [] } ]

How do I fix this ?

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