Pregunta

In laravel documentation i saw:

"You may also share a piece of data across all views:"

View::share('name', 'Steve');

So i thought this is was like a cookie (or global variable). That $test could be accessed in every view when the user is logged in. But this does not seem to be the case.

Does laravel have a function that acts like a cookies or global variable?

¿Fue útil?

Solución

you still have $_SERVER and $_COOKIE available. although you now have wrappers for those. for instance for $_SERVER['HTTP_USER_AGENT'] you'd use Request::server('HTTP_USER_AGENT'). whereas cookies have their own wrapper Cookie::get().

the View::share() is simply to have variables available within all withs, that may be included within the main view. laravel does this for instance with $errors, that is available everytime you use View::make(), but might be empty.

Otros consejos

What exactly are you trying to achieve?

If it's something you need to access in multiple places you can use Config?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top