File: /home/xedaptot/ai.naniguide.com/app/Model/AdCreative.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use App\Library\Traits\HasUid;
class AdCreative extends Model
{
use HasFactory;
use HasUid;
const STATUS_ACTIVE = 'active'; // for HasUid trait compatibility
const TYPE_IMAGE = 'image';
const TYPE_VIDEO = 'video';
const TYPE_CAROUSEL = 'carousel';
const TYPE_HTML = 'html';
const TYPES = [
self::TYPE_IMAGE,
self::TYPE_VIDEO,
self::TYPE_CAROUSEL,
self::TYPE_HTML,
];
const TYPE_LABELS = [
self::TYPE_IMAGE => 'Image',
self::TYPE_VIDEO => 'Video',
self::TYPE_CAROUSEL => 'Carousel',
self::TYPE_HTML => 'HTML',
];
const CTA_OPTIONS = [
'learn_more' => 'Learn More',
'shop_now' => 'Shop Now',
'sign_up' => 'Sign Up',
'contact_us' => 'Contact Us',
'download' => 'Download',
'get_quote' => 'Get Quote',
'book_now' => 'Book Now',
'apply_now' => 'Apply Now',
];
protected $table = 'ad_creatives';
protected $fillable = [
'uid',
'customer_id',
'ad_campaign_id',
'name',
'type',
'headline',
'primary_text',
'description',
'call_to_action',
'destination_url',
'display_url',
'image_url',
'video_url',
'html_content',
'builder_content',
'thumbnail_url',
'carousel_cards',
'metadata',
];
protected $casts = [
'builder_content' => 'json',
'carousel_cards' => 'json',
'metadata' => 'json',
];
// ── Relations ──────────────────────────────────────────────────────────
public function customer(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Customer::class, 'customer_id');
}
public function campaign(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(AdCampaign::class, 'ad_campaign_id');
}
// ── Scopes ─────────────────────────────────────────────────────────────
public function scopeOfCustomer($query, $customerId)
{
return $query->where('customer_id', $customerId);
}
public function scopeSearch($query, $keyword)
{
if (!$keyword) {
return $query;
}
return $query->where('name', 'like', '%' . $keyword . '%');
}
// ── Accessors ──────────────────────────────────────────────────────────
public function getTypeLabelAttribute(): string
{
return self::TYPE_LABELS[$this->type] ?? ucfirst($this->type);
}
// ── Factory ─────────────────────────────────────────────────────────────
protected static function newFactory()
{
return \Database\Factories\AdCreativeFactory::new();
}
}