refactor: remove global RateCardProfile singleton usage from controllers and delete unused welcome view

This commit is contained in:
I-Fun
2026-04-06 09:33:43 +07:00
parent a72eec3ead
commit 737ba24293
9 changed files with 155 additions and 268 deletions

View File

@@ -94,13 +94,11 @@ class ClientController extends Controller
public function show(Client $client): View public function show(Client $client): View
{ {
$client->load([ $client->load('category');
'category', $client->setRelation('events', $client->events()->latest()->limit(5)->get());
'events' => fn ($q) => $q->latest()->limit(5), $client->setRelation('invoices', $client->invoices()->latest()->limit(5)->get());
'invoices' => fn ($q) => $q->latest()->limit(5), $client->setRelation('contentBriefs', $client->contentBriefs()->latest()->limit(5)->get());
'contentBriefs'=> fn ($q) => $q->latest()->limit(5), $client->setRelation('mediaFiles', $client->mediaFiles()->latest()->limit(10)->get());
'mediaFiles' => fn ($q) => $q->latest()->limit(10),
]);
return view('clients.show', compact('client')); return view('clients.show', compact('client'));
} }

View File

@@ -30,8 +30,7 @@ class InvoiceController extends Controller
{ {
$clients = Client::where('status', 'active')->orderBy('name')->get(); $clients = Client::where('status', 'active')->orderBy('name')->get();
$statuses = InvoiceStatus::cases(); $statuses = InvoiceStatus::cases();
$invoiceSettings = InvoiceSettings::instance(); return view('invoices.create', compact('clients', 'statuses'));
return view('invoices.create', compact('clients', 'statuses', 'invoiceSettings'));
} }
public function store(Request $request): RedirectResponse public function store(Request $request): RedirectResponse
@@ -84,17 +83,15 @@ class InvoiceController extends Controller
public function show(Invoice $invoice): View public function show(Invoice $invoice): View
{ {
$invoice->load('client', 'items'); $invoice->load('client', 'items');
$invoiceSettings = InvoiceSettings::instance(); return view('invoices.show', compact('invoice'));
return view('invoices.show', compact('invoice', 'invoiceSettings'));
} }
public function edit(Invoice $invoice): View public function edit(Invoice $invoice): View
{ {
$clients = Client::where('status', 'active')->orderBy('name')->get(); $clients = Client::where('status', 'active')->orderBy('name')->get();
$statuses = InvoiceStatus::cases(); $statuses = InvoiceStatus::cases();
$invoiceSettings = InvoiceSettings::instance();
$invoice->load('client', 'items'); $invoice->load('client', 'items');
return view('invoices.edit', compact('invoice', 'clients', 'statuses', 'invoiceSettings')); return view('invoices.edit', compact('invoice', 'clients', 'statuses'));
} }
public function update(Request $request, Invoice $invoice): RedirectResponse public function update(Request $request, Invoice $invoice): RedirectResponse

View File

@@ -17,8 +17,7 @@ class RateCardController extends Controller
public function index(): View public function index(): View
{ {
$rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get(); $rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get();
$profile = RateCardProfile::getSingleton(); return view('rate-cards.index', compact('rateCards'));
return view('rate-cards.index', compact('rateCards', 'profile'));
} }
public function create(): View public function create(): View
@@ -88,23 +87,21 @@ class RateCardController extends Controller
public function public(): View public function public(): View
{ {
$profile = RateCardProfile::getSingleton();
$rateCards = RateCard::where('is_active', true) $rateCards = RateCard::where('is_active', true)
->orderBy('sort_order') ->orderBy('sort_order')
->orderBy('platform') ->orderBy('platform')
->get() ->get()
->groupBy('platform'); ->groupBy('platform');
return view('rate-cards.public', compact('rateCards', 'profile')); return view('rate-cards.public', compact('rateCards'));
} }
// ── Profile Settings ───────────────────────────────────────── // ── Profile Settings ─────────────────────────────────────────
public function profilePage(): View public function profilePage(): View
{ {
$profile = RateCardProfile::getSingleton();
$mediaFiles = \App\Models\MediaFile::latest()->get(); $mediaFiles = \App\Models\MediaFile::latest()->get();
return view('rate-cards.profile', compact('profile', 'mediaFiles')); return view('rate-cards.profile', compact('mediaFiles'));
} }
public function profileUpdate(Request $request): RedirectResponse public function profileUpdate(Request $request): RedirectResponse
@@ -143,7 +140,7 @@ class RateCardController extends Controller
} }
$validated['show_prices'] = $request->has('show_prices'); $validated['show_prices'] = $request->has('show_prices');
$contentShowcase = $request->input('content_showcase', []); $contentShowcase = $validated['content_showcase'] ?? [];
foreach ($contentShowcase as &$item) { foreach ($contentShowcase as &$item) {
$item['show_on_public'] = filter_var($item['show_on_public'] ?? true, FILTER_VALIDATE_BOOLEAN); $item['show_on_public'] = filter_var($item['show_on_public'] ?? true, FILTER_VALIDATE_BOOLEAN);
$item['show_on_pdf'] = filter_var($item['show_on_pdf'] ?? true, FILTER_VALIDATE_BOOLEAN); $item['show_on_pdf'] = filter_var($item['show_on_pdf'] ?? true, FILTER_VALIDATE_BOOLEAN);
@@ -206,6 +203,7 @@ class RateCardController extends Controller
public function deleteBrandLogo(Request $request) public function deleteBrandLogo(Request $request)
{ {
$request->validate(['path' => 'required|string']);
$path = $request->input('path'); $path = $request->input('path');
$profile = RateCardProfile::getSingleton(); $profile = RateCardProfile::getSingleton();
$brands = $profile->past_brands ?? []; $brands = $profile->past_brands ?? [];

View File

@@ -35,25 +35,39 @@ class InvoiceSettings extends Model
'default_tax_rate' => 'decimal:2', 'default_tax_rate' => 'decimal:2',
]; ];
protected static ?self $instance = null;
/** Always return the single settings row, creating it if absent. */ /** Always return the single settings row, creating it if absent. */
public static function instance(): self public static function instance(): self
{ {
return static::firstOrCreate([], [ if (self::$instance) {
return self::$instance;
}
self::$instance = static::firstOrCreate([], [
'invoice_prefix' => 'INV', 'invoice_prefix' => 'INV',
'invoice_next_number' => 1, 'invoice_next_number' => 1,
'accent_color' => '#FFB7C5', 'accent_color' => '#FFB7C5',
'default_tax_rate' => 2.5, 'default_tax_rate' => 2.5,
'default_currency' => 'IDR', 'default_currency' => 'IDR',
]); ]);
return self::$instance;
}
protected static function booted()
{
static::saved(fn ($model) => self::$instance = $model);
static::deleted(fn () => self::$instance = null);
} }
/** Generate the next invoice number and increment the counter. */
public static function generateNumber(): string public static function generateNumber(): string
{ {
$settings = static::instance(); $settings = static::instance();
$prefix = rtrim($settings->invoice_prefix, '-'); $prefix = rtrim($settings->invoice_prefix, '-');
$number = str_pad((string) $settings->invoice_next_number, 3, '0', STR_PAD_LEFT); $number = str_pad((string) $settings->invoice_next_number, 3, '0', STR_PAD_LEFT);
$settings->increment('invoice_next_number'); $settings->increment('invoice_next_number');
\Illuminate\Support\Facades\Cache::forget('invoice_settings');
return $prefix . '-' . $number; return $prefix . '-' . $number;
} }
} }

View File

@@ -26,16 +26,30 @@ class RateCardProfile extends Model
'content_showcase' => 'array', 'content_showcase' => 'array',
]; ];
protected static ?self $instance = null;
/** Get the singleton profile, creating defaults if needed */ /** Get the singleton profile, creating defaults if needed */
public static function getSingleton(): self public static function getSingleton(): self
{ {
return static::firstOrCreate([], [ if (self::$instance) {
return self::$instance;
}
self::$instance = static::firstOrCreate([], [
'owner_name' => config('app.name', 'Cathy Page'), 'owner_name' => config('app.name', 'Cathy Page'),
'bg_color' => '#FFF8F0', 'bg_color' => '#FFF8F0',
'accent_color' => '#FFB7C5', 'accent_color' => '#FFB7C5',
'text_color' => '#374151', 'text_color' => '#374151',
'show_prices' => true, 'show_prices' => true,
]); ]);
return self::$instance;
}
protected static function booted()
{
static::saved(fn ($model) => self::$instance = $model);
static::deleted(fn () => self::$instance = null);
} }
public function getWhatsappUrlAttribute(): ?string public function getWhatsappUrlAttribute(): ?string

View File

@@ -16,6 +16,13 @@ class AppServiceProvider extends ServiceProvider
{ {
// Inject alert badge count into all views // Inject alert badge count into all views
View::composer('*', function (\Illuminate\View\View $view): void { View::composer('*', function (\Illuminate\View\View $view): void {
if (!$view->offsetExists('profile')) {
$view->with('profile', \App\Models\RateCardProfile::getSingleton());
}
if (!$view->offsetExists('invoiceSettings')) {
$view->with('invoiceSettings', \App\Models\InvoiceSettings::instance());
}
try { try {
$alertCount = Event::upcoming(24)->count(); $alertCount = Event::upcoming(24)->count();
} catch (\Throwable) { } catch (\Throwable) {

View File

@@ -315,23 +315,23 @@
$file = !$isUrl ? \App\Models\MediaFile::find($item['file_id']) : null; $file = !$isUrl ? \App\Models\MediaFile::find($item['file_id']) : null;
@endphp @endphp
@if($file || $isUrl) @if($file || $isUrl)
<div style="display:inline-block; width:180px; margin:10px; border:1px solid rgba(0,0,0,0.1); border-radius:8px; overflow:hidden; vertical-align:top; background:#ffffff;"> <div style="display:inline-block; width:135px; margin:10px; border:1px solid rgba(0,0,0,0.1); border-radius:8px; overflow:hidden; vertical-align:top; background:#ffffff;">
<div style="height:120px; background:#F9FAFB; border-bottom:1px solid rgba(0,0,0,0.05); position:relative; text-align:center;"> <div style="height:240px; background:#F9FAFB; border-bottom:1px solid rgba(0,0,0,0.05); position:relative; text-align:center;">
@if(!empty($item['thumbnail_path']) && file_exists(storage_path('app/public/' . $item['thumbnail_path']))) @if(!empty($item['thumbnail_path']) && file_exists(storage_path('app/public/' . $item['thumbnail_path'])))
<a href="{{ $isUrl ? $item['url'] : $file->url }}" target="_blank" style="display:block; text-decoration:none; position:relative;"> <a href="{{ $isUrl ? $item['url'] : $file->url }}" target="_blank" style="display:block; text-decoration:none; position:relative;">
<img src="{{ storage_path('app/public/' . $item['thumbnail_path']) }}" style="width:100%; height:120px; object-fit:cover;"> <div style="width:100%; height:240px; background-image:url('{{ storage_path('app/public/' . $item['thumbnail_path']) }}'); background-size:cover; background-position:center; background-repeat:no-repeat;"></div>
@if(!$isUrl && $file->is_video) @if(!$isUrl && $file->is_video)
<div style="position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,0.2);"> <div style="position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,0.2);">
<div style="width:30px; height:30px; background:rgba(255,255,255,0.8); border-radius:50%; display:flex; align-items:center; justify-content:center; color:{{ $accentHex }}; font-size:16px;">▶</div> <div style="width:30px; height:30px; background:rgba(255,255,255,0.8); border-radius:50%; text-align:center; line-height:30px; color:{{ $accentHex }}; font-size:16px;">▶</div>
</div> </div>
@endif @endif
</a> </a>
@elseif(!$isUrl && $file->is_image && file_exists(storage_path('app/private/' . $file->path))) @elseif(!$isUrl && $file->is_image && file_exists(storage_path('app/private/' . $file->path)))
<a href="{{ $file->url }}" target="_blank" style="display:block; text-decoration:none;"> <a href="{{ $file->url }}" target="_blank" style="display:block; text-decoration:none;">
<img src="{{ storage_path('app/private/' . $file->path) }}" style="width:100%; height:120px; object-fit:cover;"> <div style="width:100%; height:240px; background-image:url('{{ storage_path('app/private/' . $file->path) }}'); background-size:cover; background-position:center; background-repeat:no-repeat;"></div>
</a> </a>
@else @else
<a href="{{ $isUrl ? $item['url'] : $file->url }}" target="_blank" style="display:block; text-decoration:none; color:{{ $accentHex }}; padding-top:40px; font-weight:bold;"> <a href="{{ $isUrl ? $item['url'] : $file->url }}" target="_blank" style="display:block; text-decoration:none; color:{{ $accentHex }}; padding-top:90px; font-weight:bold;">
<span style="font-size:30px; display:block;">{{ $isUrl ? '🌐' : ($file->is_video ? '🎬' : '📁') }}</span> <span style="font-size:30px; display:block;">{{ $isUrl ? '🌐' : ($file->is_video ? '🎬' : '📁') }}</span>
{{ $isUrl ? 'Open Link' : 'View File' }} {{ $isUrl ? 'Open Link' : 'View File' }}
</a> </a>

View File

@@ -111,6 +111,63 @@
gap: 14px; gap: 14px;
} }
.carousel-wrapper {
position: relative;
}
.carousel-track {
display: flex;
overflow-x: auto;
scroll-snap-type: x mandatory;
gap: 14px;
padding-bottom: 10px;
scrollbar-width: none;
}
.carousel-track::-webkit-scrollbar {
display: none;
}
.carousel-slide {
flex: 0 0 220px;
scroll-snap-align: start;
}
.carousel-btn {
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 40px;
height: 40px;
border-radius: 50%;
background: white;
border: 1px solid rgba(0,0,0,0.05);
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
color:
{{ $profile->accent_color }}
;
font-size: 20px;
font-weight: 900;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 10;
}
.carousel-btn:hover {
background: #fdfdfd;
box-shadow: 0 6px 14px rgba(0,0,0,0.15);
}
.carousel-btn.prev {
left: -20px;
}
.carousel-btn.next {
right: -20px;
}
.card { .card {
background: white; background: white;
border-radius: 24px; border-radius: 24px;
@@ -123,6 +180,17 @@
22; 22;
} }
.popup-modal {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.8);
z-index: 9999;
display: flex;
align-items: center;
justify-content: center;
padding: 20px;
}
.service { .service {
font-weight: 700; font-weight: 700;
color: #1F2937; color: #1F2937;
@@ -337,22 +405,32 @@
@if(!empty($publicShowcase)) @if(!empty($publicShowcase))
<div class="platform-section" style="margin-top:40px;"> <div class="platform-section" style="margin-top:40px;">
<div class="platform-title" style="justify-content:center;">Content Showcase</div> <div class="platform-title" style="justify-content:center;">Content Showcase</div>
@php $isCarousel = count($publicShowcase) >= 3; @endphp
@if($isCarousel)
<div class="carousel-wrapper" x-data="{
scrollPrev() { $refs.slider.scrollBy({left: -234, behavior: 'smooth'}); },
scrollNext() { $refs.slider.scrollBy({left: 234, behavior: 'smooth'}); }
}">
<button type="button" class="carousel-btn prev" @click="scrollPrev()">&#10094;</button>
<div class="carousel-track" x-ref="slider">
@else
<div class="cards"> <div class="cards">
@endif
@foreach($publicShowcase as $item) @foreach($publicShowcase as $item)
@php @php
$isUrl = ($item['file_id'] === 'url'); $isUrl = ($item['file_id'] === 'url');
$file = !$isUrl ? \App\Models\MediaFile::find($item['file_id']) : null; $file = !$isUrl ? \App\Models\MediaFile::find($item['file_id']) : null;
@endphp @endphp
@if($file || $isUrl) @if($file || $isUrl)
<div class="card" style="padding:0; overflow:hidden; display:flex; flex-direction:column;"> <div class="card {{ $isCarousel ? 'carousel-slide' : '' }}" style="padding:0; overflow:hidden; display:flex; flex-direction:column;">
<div style="flex:1; background:#F9FAFB; display:flex; align-items:center; justify-content:center; position:relative;"> <div style="flex:1; background:#F9FAFB; display:flex; align-items:center; justify-content:center; position:relative;">
@if(!empty($item['thumbnail_path'])) @if(!empty($item['thumbnail_path']))
@if(!$isUrl && $file->is_image) @if(!$isUrl && $file->is_image)
<div style="width:100%; height:180px; cursor:pointer; position:relative;" @click="popupImage = '{{ $file->url }}'; popupOpen = true;"> <div style="width:100%; aspect-ratio:9/16; cursor:pointer; position:relative;" @click="popupImage = '{{ $file->url }}'; popupOpen = true;">
<img src="{{ asset('storage/' . $item['thumbnail_path']) }}" style="width:100%; height:100%; object-fit:cover; display:block;"> <img src="{{ asset('storage/' . $item['thumbnail_path']) }}" style="width:100%; height:100%; object-fit:cover; display:block;">
</div> </div>
@else @else
<a href="{{ $isUrl ? ($item['url'] ?? '#') : $file->url }}" target="_blank" style="display:block; width:100%; height:180px; position:relative;"> <a href="{{ $isUrl ? ($item['url'] ?? '#') : $file->url }}" target="_blank" style="display:block; width:100%; aspect-ratio:9/16; position:relative;">
<img src="{{ asset('storage/' . $item['thumbnail_path']) }}" style="width:100%; height:100%; object-fit:cover; display:block;"> <img src="{{ asset('storage/' . $item['thumbnail_path']) }}" style="width:100%; height:100%; object-fit:cover; display:block;">
@if(!$isUrl && $file->is_video) @if(!$isUrl && $file->is_video)
<div style="position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,0.2);"> <div style="position:absolute; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,0.2);">
@@ -362,19 +440,19 @@
</a> </a>
@endif @endif
@elseif($isUrl) @elseif($isUrl)
<div style="height:180px; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:20px; text-align:center;"> <div style="aspect-ratio:9/16; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:20px; text-align:center;">
<span style="font-size:48px;">🌐</span> <span style="font-size:48px;">🌐</span>
<a href="{{ $item['url'] ?? '#' }}" target="_blank" style="margin-top:10px; font-size:12px; color:{{ $profile->accent_color }}; text-decoration:none; font-weight:700;">Open Link</a> <a href="{{ $item['url'] ?? '#' }}" target="_blank" style="margin-top:10px; font-size:12px; color:{{ $profile->accent_color }}; text-decoration:none; font-weight:700;">Open Link</a>
</div> </div>
@else @else
@if($file->is_image) @if($file->is_image)
<div style="width:100%; height:180px; cursor:pointer;" @click="popupImage = '{{ $file->url }}'; popupOpen = true;"> <div style="width:100%; aspect-ratio:9/16; cursor:pointer;" @click="popupImage = '{{ $file->url }}'; popupOpen = true;">
<img src="{{ $file->url }}" style="width:100%; height:100%; object-fit:cover; display:block;"> <img src="{{ $file->url }}" style="width:100%; height:100%; object-fit:cover; display:block;">
</div> </div>
@elseif($file->is_video) @elseif($file->is_video)
<video src="{{ $file->url }}" style="width:100%; height:180px; object-fit:cover; display:block;" controls></video> <video src="{{ $file->url }}" style="width:100%; aspect-ratio:9/16; object-fit:cover; display:block;" controls></video>
@else @else
<div style="height:180px; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:20px; text-align:center;"> <div style="aspect-ratio:9/16; display:flex; flex-direction:column; align-items:center; justify-content:center; padding:20px; text-align:center;">
<span style="font-size:48px;">{{ $file->icon }}</span> <span style="font-size:48px;">{{ $file->icon }}</span>
<a href="{{ $file->url }}" target="_blank" style="margin-top:10px; font-size:12px; color:{{ $profile->accent_color }}; text-decoration:none; font-weight:700;">View File</a> <a href="{{ $file->url }}" target="_blank" style="margin-top:10px; font-size:12px; color:{{ $profile->accent_color }}; text-decoration:none; font-weight:700;">View File</a>
</div> </div>
@@ -387,7 +465,13 @@
</div> </div>
@endif @endif
@endforeach @endforeach
@if($isCarousel)
</div> </div>
<button type="button" class="carousel-btn next" @click="scrollNext()">&#10095;</button>
</div>
@else
</div>
@endif
</div> </div>
@endif @endif
@@ -406,7 +490,7 @@
</div> </div>
<!-- Image Popup Modal --> <!-- Image Popup Modal -->
<div x-show="popupOpen" x-transition.opacity style="display:none; position:fixed; inset:0; background:rgba(0,0,0,0.8); z-index:9999; align-items:center; justify-content:center; padding:20px;" :style="popupOpen ? 'display:flex' : 'display:none'"> <div x-show="popupOpen" x-transition.opacity style="display:none;" class="popup-modal">
<div style="position:absolute; inset:0; cursor:pointer;" @click="popupOpen = false"></div> <div style="position:absolute; inset:0; cursor:pointer;" @click="popupOpen = false"></div>
<img :src="popupImage" style="max-width:100%; max-height:100%; object-fit:contain; position:relative; z-index:10000; border-radius:12px; box-shadow:0 10px 25px rgba(0,0,0,0.5);"> <img :src="popupImage" style="max-width:100%; max-height:100%; object-fit:contain; position:relative; z-index:10000; border-radius:12px; box-shadow:0 10px 25px rgba(0,0,0,0.5);">
<button @click="popupOpen = false" style="position:absolute; top:20px; right:20px; background:rgba(255,255,255,0.2); border:none; color:white; font-size:30px; width:40px; height:40px; border-radius:50%; cursor:pointer; z-index:10001; display:flex; align-items:center; justify-content:center;">&times;</button> <button @click="popupOpen = false" style="position:absolute; top:20px; right:20px; background:rgba(255,255,255,0.2); border:none; color:white; font-size:30px; width:40px; height:40px; border-radius:50%; cursor:pointer; z-index:10001; display:flex; align-items:center; justify-content:center;">&times;</button>

File diff suppressed because one or more lines are too long