Demers94
1 year ago

Share database data to all views from AppServiceProvider

Posted 1 year ago by Demers94

Hello,

my app has two models : Domain and Region.

I want to share all the domains and regions (fetched from the database) with all the views, so I have the following code in AppServiceProvider's boot() method :

$domains = Domain::get();
$regions = Region::get();`

View::composer('*', function($view) use($domains, $regions){`
  $view->with('domains', $domains);
  $view->with('regions', $regions);
});

This works fine, however it will not work when I'm installing the repository (ex: on my server through Laravel forge) because the tables have not yet been created in the database when this piece of code is executed.

How can I fix this?

Thanks for the help!

Please sign in or create an account to participate in this conversation.