I've been using Laravel for a long time, and I'm now writing a micro-project using Lumen.
I need to pass some variables to all views. In Laravel I can use the View::share()
function in a middleware or in the controller's constructor, but in Lumen there is no View
class, and it looks like all view functionality is simply View::make()
alias.
Is there a way to share variables to all views?
For performance reasons, Lumen doesn't register facades and service providers the way Laravel does. While the Laravel facades are included with Lumen, only some are aliased (
View
not being one of them), and only if you uncomment the$app->withFacedes();
line inbootstrap/app.php
(you can check theLaravel\Lumen\Application::withFacades
method to see which ones). So in order to use other facades such asView
, you either need to alias the facade class yourself:Or you can include it with
use
wherever needed: