title: Laravel Jetstream Inertia Shared Global App Data
body: <p>I want to share something I figured out since there's not much info out there (that I couldn't find).
  Laravel 8 with Jetstream Inertia has a few shared objects, like user, current route... You can access them in your components using the $page variable.
  I needed to add a menu array as a global variable but could not figure it out, even after finding some info on the the official Inertia documentation. It's just different in Laravel Jetstream.</p>
  <p>It wasn't until I found Laravel Jetstream's middleware for shared data (ShareInertiaData) that I figured out how to do it.</p>
  <p>Here's it is:</p>
  <ol>
  <li>Create a middleware in the app/Http/Middleware.php. I called mine ShareInertiaCustomData.</li>
  </ol>
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Inertia\Inertia;
  
  class ShareInertiaCustomData
  {
      public function handle($request, $next)
      {
          Inertia::share([
              'menu' =&gt; config('menu'),
          ]);
  
          return $next($request);
      }
  }
  </code></pre>
  <ol start="2">
  <li>Place it in the app/Http/Kernel.php</li>
  </ol>
  <pre><code>    protected $middlewareGroups = [
          'web' =&gt; [
              ...
              \App\Http\Middleware\ShareInertiaCustomData::class,
          ],
      ];
  </code></pre>
  <p>I hope that helps and no one else will have to spend hours trying to figure this out.</p>