in Laravel 5, in the share method, how can I return indexes to the view if I pass an array?

- 1 answer

Ad

I have this data

$data["isLoggedIn"] = true;
$data["isAdmin"] = true;
$data["isOrg"] = true;

and I share the data to the view this way.

view()->share('data', $this->data);

In my view (blade) I access the data like

{{ $data['isAdmin'] }}

I would like to be get the data with the key, something like:

{{ $isAdmin }}

Do I need to make a foreach array and pass each inner key?

thanks!

Ad

Answer

Ad

You can share an array directly with this syntax using the View facade:

View::share( $this->data );

Now you can access any key like this:

{{ $key }}
Ad
source: stackoverflow.com
Ad