2026-01-15 01:13:44 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2026-01-17 15:36:49 +00:00
|
|
|
use App\Enums\PostPlatform\ContentType;
|
2026-01-17 17:44:37 +00:00
|
|
|
use App\Enums\SocialAccount\Platform as SocialPlatform;
|
|
|
|
|
use App\Models\Traits\HasMedia;
|
2026-01-15 01:13:44 +00:00
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUuids;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
|
|
|
|
|
class PostPlatform extends Model
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\PostPlatformFactory> */
|
2026-01-17 17:44:37 +00:00
|
|
|
use HasFactory, HasMedia, HasUuids;
|
2026-01-15 01:13:44 +00:00
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'post_id',
|
|
|
|
|
'social_account_id',
|
2026-01-15 17:24:39 +00:00
|
|
|
'enabled',
|
2026-01-15 01:13:44 +00:00
|
|
|
'platform',
|
|
|
|
|
'content',
|
2026-01-17 15:36:49 +00:00
|
|
|
'content_type',
|
2026-01-15 01:13:44 +00:00
|
|
|
'status',
|
|
|
|
|
'platform_post_id',
|
|
|
|
|
'platform_url',
|
|
|
|
|
'error_message',
|
|
|
|
|
'published_at',
|
|
|
|
|
'meta',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
2026-01-15 17:24:39 +00:00
|
|
|
'enabled' => 'boolean',
|
2026-01-15 01:13:44 +00:00
|
|
|
'platform' => SocialPlatform::class,
|
2026-01-17 15:36:49 +00:00
|
|
|
'content_type' => ContentType::class,
|
2026-01-15 01:13:44 +00:00
|
|
|
'published_at' => 'datetime',
|
|
|
|
|
'meta' => 'array',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function post(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Post::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function socialAccount(): BelongsTo
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(SocialAccount::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsPublishing(): void
|
|
|
|
|
{
|
|
|
|
|
$this->update(['status' => 'publishing']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsPublished(string $platformPostId, ?string $platformUrl = null): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => 'published',
|
|
|
|
|
'platform_post_id' => $platformPostId,
|
|
|
|
|
'platform_url' => $platformUrl,
|
|
|
|
|
'published_at' => now(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function markAsFailed(string $errorMessage): void
|
|
|
|
|
{
|
|
|
|
|
$this->update([
|
|
|
|
|
'status' => 'failed',
|
|
|
|
|
'error_message' => $errorMessage,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|