Laravel 4.2 - Retrieve specific data on every request automatically

99 views Asked by At

I have been searching for a while but can't figure it out.

I am trying to send the staff profile information (model: StaffProfile.php) through to the page on every page request to a specific domain: staff.myurl.dev

The only way I have figured out doing it is retrieving the staff profile information in every method in every controller to send through to the views, but there has to be an easier way.

Is there a way to append content to the output of the function (sending data to the view) automatically that I do not have to specify it every time?

1

There are 1 answers

0
Björn On BEST ANSWER

Go to your routes.php and add:

View::composer('*', function($view) {
    $staffProfile = StaffProfile::find(1);
    $view->with('staffProfile', $staffProfile);
});

And in all of your views you can access the data:

{{ var_dump($staffProfile) }}