File size: 1,670 Bytes
1501522 74acf19 1501522 74acf19 1501522 74acf19 1501522 74acf19 1501522 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class SocialPost extends Model
{
use HasFactory;
protected $fillable = [
'user_id',
'recurrence_campaign_id',
'platform',
'status',
'requires_approval',
'title',
'caption',
'hashtags',
'image_url',
'video_url',
'scheduled_at',
'recurrence_occurrence_at',
'approved_at',
'posted_at',
'attempt_count',
'next_retry_at',
'external_post_id',
'error_message',
'meta',
];
protected $casts = [
'hashtags' => 'array',
'meta' => 'array',
'requires_approval' => 'boolean',
'scheduled_at' => 'datetime',
'recurrence_occurrence_at' => 'datetime',
'approved_at' => 'datetime',
'posted_at' => 'datetime',
'next_retry_at' => 'datetime',
];
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
public function recurringCampaign(): BelongsTo
{
return $this->belongsTo(SocialRecurringCampaign::class, 'recurrence_campaign_id');
}
public function fullCaption(): string
{
$hashtags = collect($this->hashtags ?? [])
->map(fn ($item) => trim((string) $item))
->filter()
->map(fn ($item) => str_starts_with($item, '#') ? $item : '#'.$item)
->implode(' ');
return trim($this->caption.($hashtags !== '' ? "\n\n{$hashtags}" : ''));
}
}
|