85 lines
3.3 KiB
PHP
85 lines
3.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Inertia\Middleware;
|
|
|
|
class HandleInertiaRequests extends 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
|
|
*/
|
|
public function version(Request $request): ?string
|
|
{
|
|
return parent::version($request);
|
|
}
|
|
|
|
/**
|
|
* Define the props that are shared by default.
|
|
*
|
|
* @see https://inertiajs.com/shared-data
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function share(Request $request): array
|
|
{
|
|
$u = $request->user();
|
|
|
|
// Fully externalized mode: do not load local Eloquent relations here.
|
|
// All feature data (stats, wallets, restrictions, etc.) must be fetched via
|
|
// the external API through proxy controllers/endpoints.
|
|
|
|
return [
|
|
...parent::share($request),
|
|
'name' => config('app.name'),
|
|
'api_url' => config('app.api_url'), // Pass API URL to frontend
|
|
'locale' => app()->getLocale(),
|
|
'availableLocales' => [
|
|
['code' => 'en', 'label' => 'English', 'flag' => 'https://flagcdn.com/w20/gb.png'],
|
|
['code' => 'de', 'label' => 'Deutsch', 'flag' => 'https://flagcdn.com/w20/de.png'],
|
|
['code' => 'es', 'label' => 'Español', 'flag' => 'https://flagcdn.com/w20/es.png'],
|
|
['code' => 'pt_BR', 'label' => 'Português (Brasil)', 'flag' => 'https://flagcdn.com/w20/br.png'],
|
|
['code' => 'tr', 'label' => 'Türkçe', 'flag' => 'https://flagcdn.com/w20/tr.png'],
|
|
['code' => 'pl', 'label' => 'Polski', 'flag' => 'https://flagcdn.com/w20/pl.png'],
|
|
],
|
|
'dir' => 'ltr',
|
|
'auth' => [
|
|
'user' => $u ? [
|
|
'id' => $u->id,
|
|
'name' => $u->name,
|
|
'username' => $u->username,
|
|
'email' => $u->email,
|
|
// Avatar: prefer uploaded DB avatar, fall back to OAuth avatar_url
|
|
'avatar' => $u->avatar,
|
|
'avatar_url' => $u->avatar_url,
|
|
'role' => $u->role,
|
|
'clan_tag' => $u->clan_tag,
|
|
'vip_level' => (int) ($u->vip_level ?? 0),
|
|
'balance' => (string) ($u->balance ?? '0'),
|
|
'stats' => $u->stats ? [
|
|
'vip_level' => (int) ($u->stats->vip_level ?? 0),
|
|
'vip_points' => (int) ($u->stats->vip_points ?? 0),
|
|
] : null,
|
|
'restrictions' => $u->restrictions()
|
|
->where('active', true)
|
|
->where(fn($q) => $q->whereNull('ends_at')->orWhere('ends_at', '>', now()))
|
|
->get(['type', 'reason', 'ends_at', 'starts_at', 'active']),
|
|
] : null,
|
|
],
|
|
'sidebarOpen' => ! $request->hasCookie('sidebar_state') || $request->cookie('sidebar_state') === 'true',
|
|
];
|
|
}
|
|
}
|