Files
Kol-Manager/app/Models/RateCardProfile.php

69 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RateCardProfile extends Model
{
protected $fillable = [
'owner_name', 'tagline', 'whatsapp',
'ig_handle', 'tiktok_handle', 'youtube_handle', 'email',
'logo_path', 'bg_color', 'accent_color', 'text_color',
'custom_footer', 'show_prices', 'access_token',
'terms_and_conditions',
'past_brands',
'brand_logo_size',
'contact_person_html',
'content_showcase',
];
protected $casts = [
'show_prices' => 'boolean',
'past_brands' => 'array',
'content_showcase' => 'array',
];
protected static ?self $instance = null;
/** Get the singleton profile, creating defaults if needed */
public static function getSingleton(): self
{
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
{
if (! $this->whatsapp) return null;
$number = preg_replace('/[^0-9]/', '', $this->whatsapp);
return "https://wa.me/{$number}";
}
public function getLogoUrlAttribute(): ?string
{
return $this->logo_path
? route('files.serve-profile-logo')
: null;
}
}