Is it safe to store auth()->user() as public property?

Is it safe to store auth()->user() as public property as I need to use it in many places across my Livewire component?

Hey, @ilianandreev
You want to register global variable in Service Provider, Or public property in Specific component?

I’m not sure I just need to interact with auth()->user() in a lot of my Livewire components

Hi,

I wouldn’t pass all the record of auth()->user() to livewire as public property, that is sent directly to the frontend. Just use the variables you need in a controlled way. You can use it inside the component but sent to the frontend only what you need to… if you need to use inside the component in several places, make it protected, is common to all the methods but is not public.

You can use View composer
Take a look here for more information: