137 lines
4.4 KiB
PHP
137 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Models\Setting;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Livewire\Component;
|
|
use Livewire\WithFileUploads;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Masmerise\Toaster\Toaster;
|
|
|
|
class SiteSettings extends Component
|
|
{
|
|
use WithFileUploads;
|
|
|
|
// Properti Site & SEO
|
|
public $site_name, $site_description, $meta_keywords;
|
|
|
|
// Properti Kontak Klinik
|
|
public $clinic_address, $clinic_phone, $clinic_email;
|
|
|
|
// Properti Koordinat (Tambahan)
|
|
public $clinic_latitude, $clinic_longitude;
|
|
|
|
// Media
|
|
public $logo, $favicon, $existing_logo, $existing_favicon;
|
|
|
|
// Media Sosial
|
|
public $social_facebook, $social_instagram, $social_twitter;
|
|
|
|
// Theme Settings
|
|
public $accent, $base;
|
|
|
|
// Properti Operasional
|
|
public $maintenance_mode, $registration_open;
|
|
|
|
public function mount()
|
|
{
|
|
// Load data dari Model Setting
|
|
$settings = [
|
|
'site_name',
|
|
'site_description',
|
|
'meta_keywords',
|
|
'clinic_address',
|
|
'clinic_phone',
|
|
'clinic_email',
|
|
'clinic_latitude',
|
|
'clinic_longitude',
|
|
'accent_color',
|
|
'base_color',
|
|
'site_logo',
|
|
'site_favicon',
|
|
'social_facebook',
|
|
'social_instagram',
|
|
'social_twitter',
|
|
'maintenance_mode',
|
|
'registration_open',
|
|
];
|
|
|
|
foreach ($settings as $key) {
|
|
$value = Setting::get($key);
|
|
|
|
if (in_array($key, ['maintenance_mode', 'registration_open'])) {
|
|
$this->{$key} = filter_var($value, FILTER_VALIDATE_BOOLEAN);
|
|
} elseif ($key === 'accent_color') {
|
|
$this->accent = $value;
|
|
} elseif ($key === 'base_color') {
|
|
$this->base = $value;
|
|
} elseif ($key === 'site_logo') {
|
|
$this->existing_logo = $value;
|
|
} elseif ($key === 'site_favicon') {
|
|
$this->existing_favicon = $value;
|
|
} else {
|
|
$this->{$key} = $value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$this->validate([
|
|
'site_name' => 'required|string|max:255',
|
|
'clinic_email' => 'nullable|email',
|
|
'clinic_latitude' => 'nullable|string', // Validasi latitude
|
|
'clinic_longitude' => 'nullable|string', // Validasi longitude
|
|
'accent' => 'required',
|
|
'base' => 'required',
|
|
'logo' => 'nullable|image|max:1024', // Max 1MB
|
|
'favicon' => 'nullable|image|max:512', // Max 512KB
|
|
]);
|
|
|
|
// Simpan Data Text
|
|
Setting::set('site_name', $this->site_name);
|
|
Setting::set('site_description', $this->site_description);
|
|
Setting::set('meta_keywords', $this->meta_keywords);
|
|
Setting::set('clinic_address', $this->clinic_address);
|
|
Setting::set('clinic_phone', $this->clinic_phone);
|
|
Setting::set('clinic_email', $this->clinic_email);
|
|
|
|
// Simpan Data Koordinat
|
|
Setting::set('clinic_latitude', $this->clinic_latitude);
|
|
Setting::set('clinic_longitude', $this->clinic_longitude);
|
|
|
|
Setting::set('accent_color', $this->accent);
|
|
Setting::set('base_color', $this->base);
|
|
Setting::set('social_facebook', $this->social_facebook);
|
|
Setting::set('social_instagram', $this->social_instagram);
|
|
Setting::set('social_twitter', $this->social_twitter);
|
|
|
|
Setting::set('maintenance_mode', $this->maintenance_mode ? 'true' : 'false');
|
|
Setting::set('registration_open', $this->registration_open ? 'true' : 'false');
|
|
|
|
// Handle Upload Logo
|
|
if ($this->logo) {
|
|
if ($this->existing_logo) Storage::disk('public')->delete(str_replace('/storage/', '', $this->existing_logo));
|
|
Setting::set('site_logo', $this->logo->store('site', 'public'));
|
|
}
|
|
|
|
// Handle Upload Favicon
|
|
if ($this->favicon) {
|
|
if ($this->existing_favicon) Storage::disk('public')->delete(str_replace('/storage/', '', $this->existing_favicon));
|
|
Setting::set('site_favicon', $this->favicon->store('site', 'public'));
|
|
}
|
|
|
|
Cache::forget('site_settings');
|
|
|
|
$this->dispatch('saved');
|
|
|
|
Toaster::success('Pengaturan klinik berhasil diperbarui!');
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.admin.site-settings');
|
|
}
|
|
}
|