title: Understanding Laravel View Composers: Where does my view composer belong?
body: <p>I am reading through the Laravel documentation to get a deeper understanding and this would be the second time I run into a bit of confusion. </p>
  
  <p>Not long ago, I was working through a Laracasts video in which we implement a View composer in our <code>AppServicesProvider</code> register method. </p>
  
  <p>Which looks like this:</p>
  
  <pre><code>public function register()
  {
      view()-&gt;composer('layouts.sidebar', function ($view) {
          $archives = \App\Post::archives();
          $tags = \App\Tag::has('posts')-&gt;pluck('name');
          $view-&gt;with(compact('archives', 'tags'));
      });
  }
  </code></pre>
  
  <p>What this does, is it makes archives and tags available for our sidebar view, which is available in almost every page. (The Laracast videos involved building a blog from scratch)</p>
  
  <p>So far so good.</p>
  
  <p>Today, as I am reading through the documentation of a view composer, I encounter <a href="https://laravel.com/docs/5.6/views#view-composers" rel="nofollow noreferrer">this example</a>:</p>
  
  <pre><code>/**
   * Register bindings in the container.
   *
   * @return void
   */
  public function boot()
  {
      // Using class based composers...
      View::composer(
          'profile', 'App\Http\ViewComposers\ProfileComposer'
      );
  
      // Using Closure based composers...
      View::composer('dashboard', function ($view) {
          //
      });
  }
  </code></pre>
  
  <p>Now, I THINK I understand creating your own <code>ComposerServiceProvider</code> and class based composers vs closure based. The source of my confusion is that this is being done in the <code>boot()</code> method vs the <code>register()</code> method.</p>
  
  <p>It's totally possible that I wrote this in the wrong place. If I think about it, it almost doesn't make sense for it to be in the <code>register()</code> method, since register should only be used to register services. The boot is called after ALL the register methods are called. If someone could clear this up for me I would appreciate it!</p>
  
  <blockquote>
    <p>Does view composer belong in the <code>register()</code> method or <code>boot()</code> method? And
    if it belongs in the <code>register()</code> method, is it just a coincidence that
    it still works for me?</p>
  </blockquote>