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

60 lines
1.2 KiB
PHP
Raw Normal View History

2025-06-29 09:37:49 +02:00
<?php
namespace App\Models;
2025-06-29 09:48:45 +02:00
use App\Events\ArticleFetched;
2025-06-29 09:37:49 +02:00
use Database\Factories\ArticleFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
2025-06-29 19:46:50 +02:00
use Illuminate\Support\Carbon;
2025-06-29 09:37:49 +02:00
/**
* @method static firstOrCreate(string[] $array)
2025-06-29 19:46:50 +02:00
* @property integer $id
* @property string $url
* @property bool|null $is_valid
* @property Carbon|null $validated_at
* @property Carbon $created_at
* @property Carbon $updated_at
2025-06-29 09:37:49 +02:00
*/
class Article extends Model
{
/** @use HasFactory<ArticleFactory> */
use HasFactory;
protected $fillable = [
'url',
2025-06-29 19:46:50 +02:00
'is_valid',
'validated_at',
2025-06-29 09:37:49 +02:00
];
public function casts(): array
{
return [
2025-06-29 19:46:50 +02:00
'validated_at' => 'datetime',
2025-06-29 09:37:49 +02:00
'created_at' => 'datetime',
2025-06-29 17:13:18 +02:00
'updated_at' => 'datetime',
2025-06-29 09:37:49 +02:00
];
}
2025-06-29 09:48:45 +02:00
2025-06-29 19:46:50 +02:00
public function isValid(): bool
{
if (is_null($this->validated_at)) {
return false;
}
if (is_null($this->is_valid)) {
return false;
}
return $this->is_valid;
}
protected static function booted(): void
2025-06-29 09:48:45 +02:00
{
static::created(function ($article) {
event(new ArticleFetched($article));
});
}
2025-06-29 09:37:49 +02:00
}