title: Accessing view data inside top level component in Laravel (v8)
body: <p>Is there a practical way of accessing a view's data on a higher level component? Let me explain:</p>
  <p>I have a <strong>Base Layout</strong> with just the core HTML tags <br/> <code>views/layouts/base.blade.php</code></p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html &gt;
      &lt;head&gt;
          &lt;title&gt;Page Title&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
          {{ $slot }}
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>A <strong>Main Layout</strong> layout component extending this one <br/> <code>views/layouts/main.blade.php</code></p>
  <pre><code>&lt;x-base-layout&gt;
      &lt;x-header-main /&gt;
      {{ $slot }}
      &lt;x-footer-main /&gt;
  &lt;/x-base-layout&gt;
  </code></pre>
  <p>Both have component classes for them to work outside the default <code>views/components</code> folder.</p>
  <p>Then, my <strong>Home View</strong> is set like this <br/> <code>views/home.blade.php</code></p>
  <pre><code>&lt;x-main-layout&gt;
      &lt;h1&gt;{{ $data['my_heading'] }}&lt;/h1&gt;
  &lt;/x-main-layout&gt;
  </code></pre>
  <p>from the <strong>HomeController</strong> <br/> <code>app/Http/Controllers/HomeController.php</code></p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  class HomeController extends Controller
  {
      public function index()
      {
          $data = { &quot;my_heading&quot; : &quot;My Heading&quot;, &quot;my_email&quot; : &quot;my@email.com&quot; };
  
          return view('home')-&gt;with(compact('data'));
      }
  }
  </code></pre>
  <p>And finally, the real issue. My <strong>Footer Main component</strong> is like this <br/> <code>views/components/footer-main.blade.php</code></p>
  <pre><code>&lt;footer&gt;
      &lt;p&gt;{{ $data['my_email'] }}&lt;/p&gt;
  &lt;/footer&gt;
  </code></pre>
  <p><em><strong>But, as you might imagine, it doesn't work. I get an error:</strong></em></p>
  <blockquote>
  <p>ErrorException
  Undefined variable: data (View:
  C:\my-project\resources\views\components\footer-main.blade.php)</p>
  </blockquote>
  <p>What would be the correct way of making this work? I know I'm probably missing some Laravel inheritance concept here, but I couldn't get which yet.</p>