0

I want to store global settings in the database, that then will be editable from cPanel. I have a model Setting, which has only 1 item with multiple columns such as siteName, language, siteDescription and etc. I want to make these accessible in every view, so do I need to do

$settings = \MyApp\Setting::find(1);

for every single controller? Is there a way to define this variable somewhere globally and have it accessible in every single controller / view ?

Or perhaps this is not the correct way to do it?

Such Much Code
  • 787
  • 1
  • 9
  • 26
  • Nevermind, I found an answer here: http://stackoverflow.com/questions/25189427/global-variable-for-all-controller-and-views – Such Much Code Jul 06 '15 at 10:27
  • You can add `view()->share('settings', $settings);` to your base controller or a service provider but since I'm sure you will not need the settings in every single view I think the best approach would be to use a wildcard view composer http://laravel.com/docs/5.1/views#view-composers. – Javi Stolz Jul 06 '15 at 12:18

1 Answers1

0

May be it's better to write that code snippet into BaseController.

or

Create a trait and write into it. use that trait in anywhere you want.

Kiran LM
  • 1,359
  • 1
  • 16
  • 29