fedi-feed-router/app/Models/PlatformChannel.php

49 lines
1.2 KiB
PHP
Raw Normal View History

2025-07-05 02:19:59 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
/**
* @method static create(array $validated)
* @property PlatformInstance $platformInstance
*/
2025-07-05 02:29:50 +02:00
class PlatformChannel extends Model
2025-07-05 02:19:59 +02:00
{
2025-07-05 02:29:50 +02:00
protected $table = 'platform_channels';
2025-07-05 02:19:59 +02:00
protected $fillable = [
'platform_instance_id',
'name',
'display_name',
2025-07-05 02:29:50 +02:00
'channel_id',
2025-07-05 02:19:59 +02:00
'description',
'is_active'
];
protected $casts = [
'is_active' => 'boolean'
];
public function platformInstance(): BelongsTo
{
return $this->belongsTo(PlatformInstance::class);
}
public function platformAccounts(): BelongsToMany
{
2025-07-05 02:29:50 +02:00
return $this->belongsToMany(PlatformAccount::class, 'platform_account_channels')
2025-07-05 02:19:59 +02:00
->withPivot(['is_active', 'priority'])
->withTimestamps();
}
public function getFullNameAttribute(): string
{
2025-07-05 02:29:50 +02:00
// For Lemmy, use /c/ prefix. Other platforms may use different formats
$prefix = $this->platformInstance->platform === 'lemmy' ? '/c/' : '/';
return $this->platformInstance->url . $prefix . $this->name;
2025-07-05 02:19:59 +02:00
}
}