From 5c1f92e48b3fbb44bd7bc1ca106e5ae4a1b4acd7 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sun, 12 Jul 2026 14:34:51 +0700 Subject: [PATCH] feat: add PWA support by updating manifest link and adding apple-touch-icon, enhancing mobile experience --- .../Controllers/PwaManifestController.php | 68 +++++++++++++++++++ resources/views/app.blade.php | 3 +- routes/web.php | 2 + 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/PwaManifestController.php diff --git a/app/Http/Controllers/PwaManifestController.php b/app/Http/Controllers/PwaManifestController.php new file mode 100644 index 0000000..c2f1f72 --- /dev/null +++ b/app/Http/Controllers/PwaManifestController.php @@ -0,0 +1,68 @@ +systemData(); + $appName = $systemData['app_name'] ?? config('app.name', 'DST Collection'); + $logoUrl = $systemData['logo_url'] ?? asset('assets/logo.png'); + + // Determine mime type from logoUrl extension + $mimeType = 'image/png'; + $lowerLogoUrl = strtolower($logoUrl); + if (str_contains($lowerLogoUrl, '.svg')) { + $mimeType = 'image/svg+xml'; + } elseif (str_contains($lowerLogoUrl, '.jpg') || str_contains($lowerLogoUrl, '.jpeg')) { + $mimeType = 'image/jpeg'; + } elseif (str_contains($lowerLogoUrl, '.webp')) { + $mimeType = 'image/webp'; + } + + $manifest = [ + 'name' => $appName, + 'short_name' => $appName, + 'description' => "{$appName} - Progressive Web App", + 'theme_color' => '#171717', + 'background_color' => '#ffffff', + 'display' => 'standalone', + 'orientation' => 'portrait', + 'scope' => '/', + 'start_url' => '/', + 'id' => '/', + 'icons' => [ + [ + 'src' => $logoUrl, + 'sizes' => '64x64', + 'type' => $mimeType, + ], + [ + 'src' => $logoUrl, + 'sizes' => '192x192', + 'type' => $mimeType, + ], + [ + 'src' => $logoUrl, + 'sizes' => '512x512', + 'type' => $mimeType, + 'purpose' => 'any', + ], + [ + 'src' => $logoUrl, + 'sizes' => '512x512', + 'type' => $mimeType, + 'purpose' => 'maskable', + ], + ], + ]; + + return response()->json($manifest) + ->header('Content-Type', 'application/manifest+json') + ->header('Cache-Control', 'no-cache, no-store, must-revalidate'); + } +} diff --git a/resources/views/app.blade.php b/resources/views/app.blade.php index de38ffa..bc20096 100644 --- a/resources/views/app.blade.php +++ b/resources/views/app.blade.php @@ -23,7 +23,8 @@ - + + diff --git a/routes/web.php b/routes/web.php index 2f46e3a..64f8e26 100644 --- a/routes/web.php +++ b/routes/web.php @@ -38,9 +38,11 @@ use App\Http\Controllers\Auth\LogoutController; use App\Http\Controllers\HomeController; use App\Http\Controllers\PushSubscriptionController; +use App\Http\Controllers\PwaManifestController; use Illuminate\Support\Facades\Route; Route::get('/', [HomeController::class, 'index'])->name('home'); +Route::get('/pwa-manifest.json', [PwaManifestController::class, 'show'])->name('pwa.manifest'); Route::middleware('guest')->group(function () { Route::get('/auth/login', [LoginController::class, 'index'])->name('login');