dogakorkmaz35's avatar

dogakorkmaz35 liked a comment+100 XP

1w ago

How can I gather all shared view data?

Hi there, in one of my projects I am trying to differentiate current laravel application's view shared data vs data that passed down as props to view file via view("file")->with($data);, I tried to create a ViewFactory class that extends and overrides Laravel's default Illuminate\View\Factory class, and returns (via its viewInstance method) my own View class that extends Illuminate\View\View, and implement my own gatherData method in that View class, I can successfully gather all the globally shared data that is registered via Illuminate\View\Factory::share(...) calls, I cant find a proper way to separate $props that is passed by controller and variables which are registered via Illuminate\View\Factory::composer(...) nor Illuminate\View\Factory::creator(...), even in constructors of these files passed $data array seems to be populated by these calls already. If anyone knows or has any slight idea how can I intercept Laravel's global variable (I know composer and creator calls may not be registering a global variable, it can be file specific, but still, not controller passed) lifecycle so at the end of the whole pipeline I can create a separated variable scope I would appreciate it a lot! Thanks in advance for any response.

Laravel version: ^13.8

dogakorkmaz35's avatar

dogakorkmaz35 started a new conversation+100 XP

1w ago

How can I gather all shared view data?

Hi there, in one of my projects I am trying to differentiate current laravel application's view shared data vs data that passed down as props to view file via view("file")->with($data);, I tried to create a ViewFactory class that extends and overrides Laravel's default Illuminate\View\Factory class, and returns (via its viewInstance method) my own View class that extends Illuminate\View\View, and implement my own gatherData method in that View class, I can successfully gather all the globally shared data that is registered via Illuminate\View\Factory::share(...) calls, I cant find a proper way to separate $props that is passed by controller and variables which are registered via Illuminate\View\Factory::composer(...) nor Illuminate\View\Factory::creator(...), even in constructors of these files passed $data array seems to be populated by these calls already. If anyone knows or has any slight idea how can I intercept Laravel's global variable (I know composer and creator calls may not be registering a global variable, it can be file specific, but still, not controller passed) lifecycle so at the end of the whole pipeline I can create a separated variable scope I would appreciate it a lot! Thanks in advance for any response.

Laravel version: ^13.8

dogakorkmaz35's avatar

dogakorkmaz35 liked a comment+100 XP

2w ago

Benefits of Livewire Volt

Bear in mind that Lary's answer is 80% wishful thinking

dogakorkmaz35's avatar

dogakorkmaz35 wrote a reply+100 XP

2mos ago

Retrieving a loaded relationship but do not hit database if missing

@booni3 I know this is old, for anyone else tho, as far as I know Laravel only considers relation "loaded" if you hit the db and load the relationship to that instance, it doesn't track the actual class setters. So you must load the relationship via Eloquent API first to get true from relationLoaded check, not by native PHP.