In your second example, you’d be able to access video
in your Blade with the following:
{{$homepage_fields['video']}}
Methods in the App namespace are available to every Blade, unless they’re overwritten by another controller–i.e. if you had a controllers/FrontPage.php
controller file that also defined homepageFields()
, the $homepage_fields
variable in views/front-page.blade.php
would contain the value returned by the controllers/FrontPage.php
version of homepageFields()
instead of the one defined in controllers/App.php
.
Personally, I don’t like to group unrelated data together in the variables I pass from my controllers to my Blades, because then my templates become more opinionated about how they handle data. That being the case, I’d separate out subheading
and video
instead of returning them as an array, but that’s a personal preference.