Server IP : / Your IP : 10.244.4.16 [ Web Server : nginx/1.25.3 System : Linux escuela-portal-app-54f56585bc-kst6g 5.15.0-1084-azure #93-Ubuntu SMP Sat Mar 15 14:12:29 UTC 2025 x86_64 User : root ( 0) PHP Version : 8.2.13 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, Domains : 0 Domains MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /proc/449/root/var/www/app/vendor/inertiajs/inertia-laravel/src/ |
Upload File : |
<?php namespace Inertia; use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Redirect; use Symfony\Component\HttpFoundation\Response; class Middleware { /** * The root template that's loaded on the first page visit. * * @see https://inertiajs.com/server-side-setup#root-template * * @var string */ protected $rootView = 'app'; /** * Determines the current asset version. * * @see https://inertiajs.com/asset-versioning * * @return string|null */ public function version(Request $request) { if (config('app.asset_url')) { return md5(config('app.asset_url')); } if (file_exists($manifest = public_path('mix-manifest.json'))) { return md5_file($manifest); } if (file_exists($manifest = public_path('build/manifest.json'))) { return md5_file($manifest); } return null; } /** * Defines the props that are shared by default. * * @see https://inertiajs.com/shared-data * * @return array */ public function share(Request $request) { return [ 'errors' => function () use ($request) { return $this->resolveValidationErrors($request); }, ]; } /** * Sets the root template that's loaded on the first page visit. * * @see https://inertiajs.com/server-side-setup#root-template * * @return string */ public function rootView(Request $request) { return $this->rootView; } /** * Handle the incoming request. * * @return Response */ public function handle(Request $request, Closure $next) { Inertia::version(function () use ($request) { return $this->version($request); }); Inertia::share($this->share($request)); Inertia::setRootView($this->rootView($request)); $response = $next($request); $response->headers->set('Vary', 'X-Inertia'); if (! $request->header('X-Inertia')) { return $response; } if ($request->method() === 'GET' && $request->header('X-Inertia-Version', '') !== Inertia::getVersion()) { $response = $this->onVersionChange($request, $response); } if ($response->isOk() && empty($response->getContent())) { $response = $this->onEmptyResponse($request, $response); } if ($response->getStatusCode() === 302 && in_array($request->method(), ['PUT', 'PATCH', 'DELETE'])) { $response->setStatusCode(303); } return $response; } /** * Determines what to do when an Inertia action returned with no response. * By default, we'll redirect the user back to where they came from. */ public function onEmptyResponse(Request $request, Response $response): Response { return Redirect::back(); } /** * Determines what to do when the Inertia asset version has changed. * By default, we'll initiate a client-side location visit to force an update. */ public function onVersionChange(Request $request, Response $response): Response { if ($request->hasSession()) { $request->session()->reflash(); } return Inertia::location($request->fullUrl()); } /** * Resolves and prepares validation errors in such * a way that they are easier to use client-side. * * @return object */ public function resolveValidationErrors(Request $request) { if (! $request->hasSession() || ! $request->session()->has('errors')) { return (object) []; } return (object) collect($request->session()->get('errors')->getBags())->map(function ($bag) { return (object) collect($bag->messages())->map(function ($errors) { return $errors[0]; })->toArray(); })->pipe(function ($bags) use ($request) { if ($bags->has('default') && $request->header('x-inertia-error-bag')) { return [$request->header('x-inertia-error-bag') => $bags->get('default')]; } if ($bags->has('default')) { return $bags->get('default'); } return $bags->toArray(); }); } }