HandleInertiaRequests.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Http\Middleware;
  3. use App\Models\Company;
  4. use Illuminate\Http\Request;
  5. use Inertia\Middleware;
  6. class HandleInertiaRequests extends Middleware
  7. {
  8. /**
  9. * The root template that's loaded on the first page visit.
  10. *
  11. * @see https://inertiajs.com/server-side-setup#root-template
  12. * @var string
  13. */
  14. protected $rootView = "app";
  15. /**
  16. * Determines the current asset version.
  17. *
  18. * @see https://inertiajs.com/asset-versioning
  19. * @param \Illuminate\Http\Request $request
  20. * @return string|null
  21. */
  22. public function version(Request $request): ?string
  23. {
  24. return parent::version($request);
  25. }
  26. /**
  27. * Defines the props that are shared by default.
  28. *
  29. * @see https://inertiajs.com/shared-data
  30. * @param \Illuminate\Http\Request $request
  31. * @return array
  32. */
  33. public function share(Request $request): array
  34. {
  35. return array_merge(parent::share($request), [
  36. "auth.user" => fn() => $request->user() ?? null,
  37. "app.company.name" => fn() => Company::first()->name ?? null,
  38. "flash" => function () use ($request) {
  39. return [
  40. "success" => $request->session()->get("success"),
  41. "error" => $request->session()->get("error"),
  42. "warning" => $request->session()->get("warning"),
  43. ];
  44. },
  45. ]);
  46. }
  47. }