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.
It wasn't until I found Laravel Jetstream's middleware for shared data (ShareInertiaData) that I figured out how to do it.
Here's it is:
- Create a middleware in the app/Http/Middleware.php. I called mine ShareInertiaCustomData.
<?php
namespace App\Http\Middleware;
use Inertia\Inertia;
class ShareInertiaCustomData
{
public function handle($request, $next)
{
Inertia::share([
'menu' => config('menu'),
]);
return $next($request);
}
}
- Place it in the app/Http/Kernel.php
protected $middlewareGroups = [
'web' => [
...
\App\Http\Middleware\ShareInertiaCustomData::class,
],
];
I hope that helps and no one else will have to spend hours trying to figure this out.