Hello,
You can pass a variable to multiple views by adding this to the boot method of your AppServiceProvider
View::composer('*', function ($view) {
$now = Carbon::now();
$view->with('now', $now);
});
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have a header page, which is included (@include) in a master layout page. I would like to display users day and date on the header row.
As I research, I see that things can be flexible with Carbon.
But My header area does not have a controller (or a route as it is part of all pages) from which I can pass data to view. Does that mean I have to pass Carbon to each view? How would enable/override it so that I can call dates and time from views directly?
If not with Carbon, what's the easiest way for me to show dates, time in Blade views?
Hello,
You can pass a variable to multiple views by adding this to the boot method of your AppServiceProvider
View::composer('*', function ($view) {
$now = Carbon::now();
$view->with('now', $now);
});
Please or to participate in this conversation.