2020-04-10 20:32:12 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use App\Http\Resources\UserResource;
|
2021-11-19 00:39:34 +01:00
|
|
|
use App\Setting\GeneralSettings;
|
2021-07-17 16:10:45 +02:00
|
|
|
use Closure;
|
|
|
|
use Session;
|
2020-04-10 20:32:12 +02:00
|
|
|
|
|
|
|
class InertiaShareMiddleware
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
|
|
|
\Inertia::share([
|
2021-04-11 01:25:40 +02:00
|
|
|
'auth' => ['user' => auth()->check() ? new UserResource(auth()->user()) : null],
|
2021-04-11 10:17:30 +02:00
|
|
|
'search' => $request->query('search', ''),
|
2021-10-30 00:49:36 +02:00
|
|
|
'flash' => session()->get('flash'),
|
2021-04-11 01:25:40 +02:00
|
|
|
'menu' => function() {
|
|
|
|
return session()->get('menu');
|
|
|
|
},
|
2020-04-10 20:32:12 +02:00
|
|
|
'errors' => function () {
|
|
|
|
return Session::get('errors')
|
|
|
|
? Session::get('errors')->getBag('default')->getMessages()
|
|
|
|
: (object) [];
|
|
|
|
},
|
|
|
|
'title' => function() {
|
|
|
|
return session()->get('title', '');
|
2021-11-19 00:39:34 +01:00
|
|
|
},
|
|
|
|
'settings' => [
|
|
|
|
'modules' => app(GeneralSettings::class)->modules,
|
|
|
|
]
|
2020-04-10 20:32:12 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$response = $next($request);
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|