title: How to fetch and display data from db inside a common layout file and to display on all views in laravel 5.2
body: <p>Im new to laravel and im doing a study project in laravel 5.2. I had created a web template, various pages and given their routes, created corresponding controllers and models required to display the webpages. The datas on each of the webpages is fetched from the database. Upto this part its working fine. Right now the logo and some header information in the website is hard-coded inside header.blade.php which i stored inside views/includes folder and it is called from the view/layouts folder via default.blade.php and fetching data on each page as @extends('layouts.default'). I want to fetch that header data also from database and it has to be shown on all the webpages. </p>
  
  <p>Below given is my header.blade.php file code:</p>
  
  <pre><code>&lt;div class="top"&gt;
      &lt;div class="zerogrid" align="center" style="padding-bottom:2px; padding-top:2px;"&gt;
          &lt;ul class="number f-left"&gt;
              &lt;li class="mail"&gt;&lt;p&gt;&lt;a href="mailto:email-comes-from-db-here"&gt;&lt;font color="#FFFFFF"&gt;email-number-comes-from-db-here&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
              &lt;li class="phone"&gt;&lt;p&gt;&lt;a href="tel:phone-number-comes-from-db-here"&gt;&lt;font color="#FFFFFF"&gt;phone-number-comes-from-db-here&lt;/font&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
          &lt;/ul&gt;
          &lt;ul class="top-social f-right" style="padding-bottom:5px;"&gt;
              &lt;li&gt;&lt;a href="https://facebook.com/page-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-facebook"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="https://plus.google.com/page-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-google-plus"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="https://twitter.com/page-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-twitter"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="https://linkedin.com/page-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-linkedin"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="https://youtube.com/page-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-youtube"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="http://website-name-comes-from-db-here" target="_blank"&gt;&lt;i class="fa fa-globe"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;                
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
      &lt;div class="zerogrid"&gt;
          &lt;center&gt;&lt;div class="logo"&gt;&lt;img src="{{ asset('assets/images/logo-image-name-comes-from-db-here') }}"&gt;&lt;/div&gt;&lt;/center&gt;
      &lt;/div&gt;
  &lt;div class="site-title"&gt;
      &lt;div class="zerogrid"&gt;
          &lt;div class="row"&gt;
              &lt;h2 class="t-center"&gt;Slogan comes from db here&lt;/h2&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Below given is my routes file code(routes.php):</p>
  
  <pre><code>Route::get('/', 'GuestController@home');
  Route::get('aboutus', 'GuestController@aboutus');
  Route::get('services', 'GuestController@services');
  </code></pre>
  
  <p>Below given is my controller file code(GuestController.php):</p>
  
  <pre><code>&lt;?php
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
  use App\Http\Requests;
  use App\Http\Controllers\Controller;
  use DB;
  class GuestController extends Controller
  {
      public function home() {
          return view('guest.home');
      }   
      public function aboutus() {
          $result=DB::table('contents')-&gt;where('menuname','aboutus')-&gt;get();
          return view('guest.aboutus')-&gt;with('data',$result);
      }
      public function services() {
          $result=DB::table('contents')-&gt;where('menuname','services')-&gt;get();
          return view('guest.services')-&gt;with('data',$result);
      }
  }
  </code></pre>
  
  <p>For displaying each webpage data from db table on a single webpage is already done via routes. But to display the same header data from db to all my pages, what modification in routes/controller files i have to do? Please help. Thanks in advance...</p>