refactor: remove global RateCardProfile singleton usage from controllers and delete unused welcome view
This commit is contained in:
@@ -94,13 +94,11 @@ class ClientController extends Controller
|
||||
|
||||
public function show(Client $client): View
|
||||
{
|
||||
$client->load([
|
||||
'category',
|
||||
'events' => fn ($q) => $q->latest()->limit(5),
|
||||
'invoices' => fn ($q) => $q->latest()->limit(5),
|
||||
'contentBriefs'=> fn ($q) => $q->latest()->limit(5),
|
||||
'mediaFiles' => fn ($q) => $q->latest()->limit(10),
|
||||
]);
|
||||
$client->load('category');
|
||||
$client->setRelation('events', $client->events()->latest()->limit(5)->get());
|
||||
$client->setRelation('invoices', $client->invoices()->latest()->limit(5)->get());
|
||||
$client->setRelation('contentBriefs', $client->contentBriefs()->latest()->limit(5)->get());
|
||||
$client->setRelation('mediaFiles', $client->mediaFiles()->latest()->limit(10)->get());
|
||||
|
||||
return view('clients.show', compact('client'));
|
||||
}
|
||||
|
||||
@@ -28,10 +28,9 @@ class InvoiceController extends Controller
|
||||
|
||||
public function create(): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
$invoiceSettings = InvoiceSettings::instance();
|
||||
return view('invoices.create', compact('clients', 'statuses', 'invoiceSettings'));
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
return view('invoices.create', compact('clients', 'statuses'));
|
||||
}
|
||||
|
||||
public function store(Request $request): RedirectResponse
|
||||
@@ -84,17 +83,15 @@ class InvoiceController extends Controller
|
||||
public function show(Invoice $invoice): View
|
||||
{
|
||||
$invoice->load('client', 'items');
|
||||
$invoiceSettings = InvoiceSettings::instance();
|
||||
return view('invoices.show', compact('invoice', 'invoiceSettings'));
|
||||
return view('invoices.show', compact('invoice'));
|
||||
}
|
||||
|
||||
public function edit(Invoice $invoice): View
|
||||
{
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
$invoiceSettings = InvoiceSettings::instance();
|
||||
$clients = Client::where('status', 'active')->orderBy('name')->get();
|
||||
$statuses = InvoiceStatus::cases();
|
||||
$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
|
||||
|
||||
@@ -17,8 +17,7 @@ class RateCardController extends Controller
|
||||
public function index(): View
|
||||
{
|
||||
$rateCards = RateCard::orderBy('sort_order')->orderBy('platform')->get();
|
||||
$profile = RateCardProfile::getSingleton();
|
||||
return view('rate-cards.index', compact('rateCards', 'profile'));
|
||||
return view('rate-cards.index', compact('rateCards'));
|
||||
}
|
||||
|
||||
public function create(): View
|
||||
@@ -88,23 +87,21 @@ class RateCardController extends Controller
|
||||
|
||||
public function public(): View
|
||||
{
|
||||
$profile = RateCardProfile::getSingleton();
|
||||
$rateCards = RateCard::where('is_active', true)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('platform')
|
||||
->get()
|
||||
->groupBy('platform');
|
||||
|
||||
return view('rate-cards.public', compact('rateCards', 'profile'));
|
||||
return view('rate-cards.public', compact('rateCards'));
|
||||
}
|
||||
|
||||
// ── Profile Settings ─────────────────────────────────────────
|
||||
|
||||
public function profilePage(): View
|
||||
{
|
||||
$profile = RateCardProfile::getSingleton();
|
||||
$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
|
||||
@@ -143,7 +140,7 @@ class RateCardController extends Controller
|
||||
}
|
||||
|
||||
$validated['show_prices'] = $request->has('show_prices');
|
||||
$contentShowcase = $request->input('content_showcase', []);
|
||||
$contentShowcase = $validated['content_showcase'] ?? [];
|
||||
foreach ($contentShowcase as &$item) {
|
||||
$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);
|
||||
@@ -206,6 +203,7 @@ class RateCardController extends Controller
|
||||
|
||||
public function deleteBrandLogo(Request $request)
|
||||
{
|
||||
$request->validate(['path' => 'required|string']);
|
||||
$path = $request->input('path');
|
||||
$profile = RateCardProfile::getSingleton();
|
||||
$brands = $profile->past_brands ?? [];
|
||||
|
||||
@@ -35,25 +35,39 @@ class InvoiceSettings extends Model
|
||||
'default_tax_rate' => 'decimal:2',
|
||||
];
|
||||
|
||||
protected static ?self $instance = null;
|
||||
|
||||
/** Always return the single settings row, creating it if absent. */
|
||||
public static function instance(): self
|
||||
{
|
||||
return static::firstOrCreate([], [
|
||||
if (self::$instance) {
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
self::$instance = static::firstOrCreate([], [
|
||||
'invoice_prefix' => 'INV',
|
||||
'invoice_next_number' => 1,
|
||||
'accent_color' => '#FFB7C5',
|
||||
'default_tax_rate' => 2.5,
|
||||
'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
|
||||
{
|
||||
$settings = static::instance();
|
||||
$prefix = rtrim($settings->invoice_prefix, '-');
|
||||
$number = str_pad((string) $settings->invoice_next_number, 3, '0', STR_PAD_LEFT);
|
||||
$settings->increment('invoice_next_number');
|
||||
\Illuminate\Support\Facades\Cache::forget('invoice_settings');
|
||||
return $prefix . '-' . $number;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,16 +26,30 @@ class RateCardProfile extends Model
|
||||
'content_showcase' => 'array',
|
||||
];
|
||||
|
||||
protected static ?self $instance = null;
|
||||
|
||||
/** Get the singleton profile, creating defaults if needed */
|
||||
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'),
|
||||
'bg_color' => '#FFF8F0',
|
||||
'accent_color' => '#FFB7C5',
|
||||
'text_color' => '#374151',
|
||||
'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
|
||||
|
||||
@@ -16,6 +16,13 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
// Inject alert badge count into all views
|
||||
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 {
|
||||
$alertCount = Event::upcoming(24)->count();
|
||||
} catch (\Throwable) {
|
||||
|
||||
Reference in New Issue
Block a user