Answer the question
In order to leave comments, you need to log in
How to pass a variable to layouts?
Hello. Tell me how it's done. There is a controller and there are two variables (one variable is the records, the second is the number of records), from the controller I pass the first variable to the view, everything is ok, then I need to transfer the second variable to the layout (that is, to the main template) which includes the view in which I pass the first variable. How can I do that?
controller:
$user = User::find(1);
$unreadNotifications = $user->notifications()->unread()->get();
$notifications = $user->notifications()->unread()->count();
return view('user.notifications', [
'unreadNotifications' => $unreadNotifications,
]);
$notifications
I need to pass in the layouts which includes the viewuser.notifications
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question