I want to return multiple variable to my view.
$currentUser = Auth::user();
$needToBePassed = "Lorem Ipsum"
View::share ( 'currentUser', $currentUser);
This code works fine, however how can if I also want to share $needToBePassed
, what should I do?
Is rewriting it is a good practice?
View::share ( 'currentUser', $currentUser);
View::share ( 'needToBePassed', $needToBePassed);
You can pass an array of data,
$data = array(
'currentUser' => $currentUser,
'needToBePassed' => $needToBePassed,
);
View::share('data', $data);
I know the question is already answered, but maybe I can still help a few people by adding this solution. This way you don't have to change all your views.
I was looking for a way to solve this issue without changes all my views.
$currentUser = Auth::user();
$needToBePassed = "Lorem Ipsum";
View::share(['currentUser' => $currentUser, 'needToBePassed' => $needToBePassed]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With