From 67ee140ba74f80240abba53b423f8c5f3987da62 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Sat, 20 Jun 2026 11:01:32 +0700 Subject: [PATCH] feat: add favicon support and update related configurations in SystemService, SystemRequest, and views for improved branding --- app/Http/Middleware/HandleInertiaRequests.php | 1 + .../Requests/Admin/System/Setting/SystemRequest.php | 6 ++++-- app/Models/SystemConfiguration.php | 1 + app/Services/System/Setting/SystemService.php | 10 ++++++++++ .../js/components/admin/setting/SystemSection.vue | 11 ++++++++++- resources/js/types/global.d.ts | 1 + resources/js/types/setting.ts | 1 + resources/views/app.blade.php | 2 +- 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index bde195a..217e8e1 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -46,6 +46,7 @@ public function share(Request $request): array 'name' => fn () => app(SystemSettings::class)->app_name, 'address' => fn () => app(SystemSettings::class)->address, 'logo_url' => fn () => app(SystemService::class)->systemData()['logo_url'] ?? asset('assets/logo.png'), + 'favicon_url' => fn () => app(SystemService::class)->systemData()['favicon_url'] ?? null, 'login_cover_url' => fn () => app(SystemService::class)->systemData()['login_cover_url'] ?? null, 'auth' => fn () => [ 'user' => $request->user() ? [ diff --git a/app/Http/Requests/Admin/System/Setting/SystemRequest.php b/app/Http/Requests/Admin/System/Setting/SystemRequest.php index 7ed61f6..568bb9d 100644 --- a/app/Http/Requests/Admin/System/Setting/SystemRequest.php +++ b/app/Http/Requests/Admin/System/Setting/SystemRequest.php @@ -24,8 +24,9 @@ public function rules(): array 'email' => ['required', 'email', 'max:100'], 'phone' => ['required', 'string', 'max:20', new PhoneNumber], 'address' => ['required', 'string'], - 'logo' => ['required', 'image', 'max:2048'], - 'login_cover' => ['required', 'image', 'max:5120'], + 'logo' => ['nullable', 'image', 'max:2048'], + 'favicon' => ['nullable', 'image', 'max:1024'], + 'login_cover' => ['nullable', 'image', 'max:5120'], ]; } @@ -41,6 +42,7 @@ public function attributes(): array 'phone' => 'nomor telepon', 'address' => 'alamat', 'logo' => 'logo', + 'favicon' => 'favicon', 'login_cover' => 'cover login', ]; } diff --git a/app/Models/SystemConfiguration.php b/app/Models/SystemConfiguration.php index 5212dc0..69d79f3 100644 --- a/app/Models/SystemConfiguration.php +++ b/app/Models/SystemConfiguration.php @@ -29,6 +29,7 @@ public static function instance(): self public function registerMediaCollections(): void { $this->addMediaCollection('logo')->singleFile(); + $this->addMediaCollection('favicon')->singleFile(); $this->addMediaCollection('login_cover')->singleFile(); } } diff --git a/app/Services/System/Setting/SystemService.php b/app/Services/System/Setting/SystemService.php index 6c1588e..3db6359 100644 --- a/app/Services/System/Setting/SystemService.php +++ b/app/Services/System/Setting/SystemService.php @@ -22,6 +22,7 @@ public function systemData(): array $configuration->load('media'); $logo = MediaPresenter::first($configuration, 'logo'); + $favicon = MediaPresenter::first($configuration, 'favicon'); $loginCover = MediaPresenter::first($configuration, 'login_cover'); return [ @@ -31,6 +32,7 @@ public function systemData(): array 'phone' => $settings->phone, 'address' => $settings->address, 'logo_url' => $logo['url'] ?? null, + 'favicon_url' => $favicon['url'] ?? null, 'login_cover_url' => $loginCover['url'] ?? null, ]; } @@ -51,6 +53,10 @@ public function updateSystem(array $validated): void $this->mediaService->replaceSingleFile($configuration, $validated['logo'], 'logo', 'logo'); } + if (isset($validated['favicon']) && $validated['favicon'] instanceof UploadedFile) { + $this->mediaService->replaceSingleFile($configuration, $validated['favicon'], 'favicon', 'favicon'); + } + if (isset($validated['login_cover']) && $validated['login_cover'] instanceof UploadedFile) { $this->mediaService->replaceSingleFile($configuration, $validated['login_cover'], 'login_cover', 'login-cover'); } @@ -61,6 +67,10 @@ public function updateSystem(array $validated): void $errors['logo'] = 'Logo wajib diisi.'; } + if (! $configuration->hasMedia('favicon')) { + $errors['favicon'] = 'Favicon wajib diisi.'; + } + if (! $configuration->hasMedia('login_cover')) { $errors['login_cover'] = 'Cover login wajib diisi.'; } diff --git a/resources/js/components/admin/setting/SystemSection.vue b/resources/js/components/admin/setting/SystemSection.vue index 73072d9..326c716 100644 --- a/resources/js/components/admin/setting/SystemSection.vue +++ b/resources/js/components/admin/setting/SystemSection.vue @@ -23,6 +23,7 @@ const form = useForm({ phone: props.data.phone ?? '', address: props.data.address ?? '', logo: null as File | null, + favicon: null as File | null, login_cover: null as File | null, }); @@ -39,6 +40,10 @@ function buildFormData(): FormData { formData.append('logo', form.logo); } + if (form.favicon) { + formData.append('favicon', form.favicon); + } + if (form.login_cover) { formData.append('login_cover', form.login_cover); } @@ -119,11 +124,15 @@ function submit() { - +