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

63 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use App\Events\ArticleFetched;
use Database\Factories\ArticleFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;
/**
* @method static firstOrCreate(string[] $array)
* @property integer $id
* @property string $url
* @property bool|null $is_valid
* @property Carbon|null $validated_at
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class Article extends Model
{
/** @use HasFactory<ArticleFactory> */
use HasFactory;
protected $fillable = [
'url',
'title',
'description',
'is_valid',
'fetched_at',
'validated_at',
];
public function casts(): array
{
return [
'fetched_at' => 'datetime',
'validated_at' => 'datetime',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
}
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
{
static::created(function ($article) {
event(new ArticleFetched($article));
});
}
}