title: Why is my singleton view composer not working, what am I missing?
body: <p>I have created this view composer in my project. But when I run the site it runs the class multiple times. I am using partial loops to generate some menus ang this is the place where views are called many times. And because I set the view composer ( <code>view()-&gt;composer('*', ViewComposer::class);</code> ) in every view the class is called more than 200 times. I didn't use view composer and singletons before so I am not sure where I am doing wrong.</p>
  
  <p>This is my provider:
      
  
  <pre><code>namespace App\Providers;
  
  use App\Http\Composers\ViewComposer;
  use Illuminate\Support\ServiceProvider;
  
  class ViewComposerServiceProvider extends ServiceProvider
  {
      /**
       * Bootstrap services.
       *
       * @return void
       */
      public function boot()
      {
          view()-&gt;composer('*', ViewComposer::class);
      }
  
      /**
       * Register services.
       *
       * @return void
       */
      public function register()
      {
          $this-&gt;app-&gt;singleton(ViewComposer::class);
      }
  
  }
  </code></pre>
  
  <p>and this is my view composer</p>
  
  <pre><code>&lt;?php 
  
  namespace App\Http\Composers;
  
  use Illuminate\Contracts\View\View;
  
  class ViewComposer
  {
      public function compose(View $view)
      {
          \Log::debug('view composer runned');
          if( auth()-&gt;check() ){
              $permissions = auth()-&gt;user()-&gt;permissions()
          }
  
          $view-&gt;with( "permissions", $permissions);
      }
  }
  </code></pre>
  
  <p>This works so the service provider is registered in config/app.php. But as I said the it runs the sql query and the class many many times. Where am I doing wrong?</p>