hsntngr
158
3
Laravel

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

Posted 6 months 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")
                ->with("media")
                ->orderBy("id", "desc")
                ->take(5)
                ->get();

            $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.

Reply to

Use Markdown with GitHub-flavored code blocks.