Files
Kol-Manager/app/Models/SocialStat.php
2026-04-01 08:04:56 +07:00

41 lines
1014 B
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SocialStat extends Model
{
protected $fillable = [
'platform', 'handle', 'followers', 'following', 'posts_count',
'engagement_rate', 'avg_views', 'avg_likes', 'avg_comments',
'recorded_date', 'raw_data',
];
protected $casts = [
'recorded_date' => 'date',
'raw_data' => 'array',
'engagement_rate' => 'decimal:2',
];
public function getFormattedFollowersAttribute(): string
{
$n = $this->followers;
if ($n >= 1_000_000) return round($n / 1_000_000, 1) . 'M';
if ($n >= 1_000) return round($n / 1_000, 1) . 'K';
return (string) $n;
}
public function getPlatformIconAttribute(): string
{
return match($this->platform) {
'instagram' => '📸',
'tiktok' => '🎵',
'youtube' => '▶️',
default => '📱',
};
}
}