title: View Composer not working in my Laravel App
body: <p>I am trying to share variables on multiple views so i tried the view composer but it is not working as its not passing variables and is there any way to debug it</p>
  
  <p><strong>ComposerServiceProvider.php</strong>
         
  
  <pre><code>namespace App\Providers;
  
  use Illuminate\Support\ServiceProvider;
  
  class ComposerServiceProvider extends ServiceProvider
  {
      /**
       * Bootstrap services.
       *
       * @return void
       */
      public function boot()
      {
          view()-&gt;composer(
              'layouts.admin.dashboard',
              'App\Http\ViewComposers\StatComposer'
          );
      }
  
      /**
       * Register services.
       *
       * @return void
       */
      public function register()
      {
          //
      }
  }
  </code></pre>
  
  <p>So now here will be the Composer File</p>
  
  <p><strong>StatComposer.php</strong></p>
  
  <pre><code>   &lt;?php
  
  namespace App\Http\ViewComposers;
  
  use Analytics;
  use Spatie\Analytics\Period;
  use App\Libraries\GoogleAnalytics;
  use Illuminate\Http\Request;
  use Illuminate\View\View;
  
  class StatComposer
  {
      /**
       * Create a movie composer.
       *
       * @return void
       */
      public function __construct()
      {
          $result = GoogleAnalytics::topCountries();
          $country = $result-&gt;pluck('country');
          $country_sessions = $result-&gt;pluck('sessions');
  
          $topBrowsers = GoogleAnalytics::topBrowsers();
          $browser = $topBrowsers-&gt;pluck('browser');
          $browser_sessions = $topBrowsers-&gt;pluck('sessions');
  
          $totalPageViews = GoogleAnalytics::fetchVisitorsAndPageViews();
          $date = $totalPageViews-&gt;pluck('date');
          $visitors = $totalPageViews-&gt;pluck('visitors');
          $pageViews = $totalPageViews-&gt;pluck('pageViews');
      }
  
      /**
       * Bind data to the view.
       *
       * @param  View  $view
       * @return void
       */
      public function compose(View $view)
      {
          $view-&gt;with('country', 'country_sessions', 'browser', 'browser_sessions','date','visitors','pageViews');
      }
  }
  </code></pre>
  
  <p>So I am unable to find way to debug it as the variables are not passing to the view i am trying to pass them to and the view is giving error of undefined variable. </p>