initial commit
This commit is contained in:
40
app/Models/SocialStat.php
Normal file
40
app/Models/SocialStat.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?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 => '📱',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user