Anybody had similar problem?
Sharing data with namespaced view
Hello guys,
I am working with laravel-modules package, which provides namespaces for my views(e.g. ecommerce).
I want to share data with single view which is located inside this module.
I have tried:
View::composer(
'ecommercegiftcards.pages.default.gift-cards',
fn($view) => $view->with('giftCards', $giftCards)
);
This is not working, however if I share data with all views(by setting * as view name) the $giftCards variable is accessible from this view(gift-cards.blade.php).
@Sinnbeck I made a typo above. I tried:
View::composer(
'ecommercegiftcards::pages.default.gift-cards',
fn($view) => $view->with('giftCards', $giftCards)
);
With double semi colon but it did not work. I tried doing only this. without specifying namespace:
View::composer(
'pages.default.gift-cards',
fn($view) => $view->with('giftCards', $giftCards)
);
And it worked. Laravel somehow resolves it to current namespace and it does not need it in this compoer function.
So you only need to specify path and not the namespace of views you are sharing data with.
Please or to participate in this conversation.