fedi-feed-router/app/Models/Feed.php
2025-07-05 02:37:38 +02:00

71 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
/**
* @property int $id
* @property string $name
* @property string $url
* @property string $type
* @property string $language
* @property string $description
* @property array $settings
* @property bool $is_active
* @property Carbon $last_fetched_at
* @property Carbon $created_at
* @property Carbon $updated_at
* @method static create(array $validated)
* @method static orderBy(string $string, string $string1)
*/
class Feed extends Model
{
protected $fillable = [
'name',
'url',
'type',
'language',
'description',
'settings',
'is_active',
'last_fetched_at'
];
protected $casts = [
'settings' => 'array',
'is_active' => 'boolean',
'last_fetched_at' => 'datetime'
];
public function getTypeDisplayAttribute(): string
{
return match ($this->type) {
'website' => 'Website',
'rss' => 'RSS Feed',
default => 'Unknown'
};
}
public function getStatusAttribute(): string
{
if (!$this->is_active) {
return 'Inactive';
}
if (!$this->last_fetched_at) {
return 'Never fetched';
}
$hoursAgo = $this->last_fetched_at->diffInHours(now());
if ($hoursAgo < 2) {
return 'Recently fetched';
} elseif ($hoursAgo < 24) {
return "Fetched {$hoursAgo}h ago";
} else {
return "Fetched " . $this->last_fetched_at->diffForHumans();
}
}
}