You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
monitor-doc/app/Http/Middleware/HandleInertiaRequests.php

66 lines
1.6 KiB
PHTML

2 years ago
<?php
namespace App\Http\Middleware;
use App\Models\Document;
use App\Models\DocumentReminder as ModelsDocumentReminder;
use App\Models\Notification;
use App\Models\User;
2 years ago
use Illuminate\Http\Request;
use Inertia\Middleware;
use Tightenco\Ziggy\Ziggy;
class HandleInertiaRequests extends Middleware
{
/**
* The root template that is loaded on the first page visit.
*
* @var string
*/
protected $rootView = 'app';
/**
* Determine the current asset version.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
public function version(Request $request)
{
return parent::version($request);
}
/**
* Define the props that are shared by default.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function share(Request $request)
{
if (auth()->check()) {
$user = User::find(auth()->user()->id)->load('role.permissions');
} else {
$user = null;
}
2 years ago
return array_merge(parent::share($request), [
'auth' => [
'user' => $user,
2 years ago
],
'ziggy' => function () use ($request) {
return array_merge((new Ziggy)->toArray(), [
'location' => $request->url(),
]);
},
'flash' => [
'message' => fn () => $request->session()->get('message')
],
'notify' => [
'notifications' => [],
'notification_has_unread' => 0
]
2 years ago
]);
}
}