96 lines
2.1 KiB
PHP
96 lines
2.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Database\Factories\RouteArticleFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||
|
|
use Illuminate\Support\Carbon;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @property int $id
|
||
|
|
* @property int $feed_id
|
||
|
|
* @property int $platform_channel_id
|
||
|
|
* @property int $article_id
|
||
|
|
* @property string $approval_status
|
||
|
|
* @property Carbon|null $validated_at
|
||
|
|
* @property Carbon $created_at
|
||
|
|
* @property Carbon $updated_at
|
||
|
|
*/
|
||
|
|
class RouteArticle extends Model
|
||
|
|
{
|
||
|
|
/** @use HasFactory<RouteArticleFactory> */
|
||
|
|
use HasFactory;
|
||
|
|
|
||
|
|
protected $fillable = [
|
||
|
|
'feed_id',
|
||
|
|
'platform_channel_id',
|
||
|
|
'article_id',
|
||
|
|
'approval_status',
|
||
|
|
'validated_at',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected $casts = [
|
||
|
|
'validated_at' => 'datetime',
|
||
|
|
];
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return BelongsTo<Route, $this>
|
||
|
|
*/
|
||
|
|
public function route(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Route::class, 'feed_id', 'feed_id')
|
||
|
|
->where('platform_channel_id', $this->platform_channel_id);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return BelongsTo<Article, $this>
|
||
|
|
*/
|
||
|
|
public function article(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Article::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return BelongsTo<Feed, $this>
|
||
|
|
*/
|
||
|
|
public function feed(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Feed::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return BelongsTo<PlatformChannel, $this>
|
||
|
|
*/
|
||
|
|
public function platformChannel(): BelongsTo
|
||
|
|
{
|
||
|
|
return $this->belongsTo(PlatformChannel::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isPending(): bool
|
||
|
|
{
|
||
|
|
return $this->approval_status === 'pending';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isApproved(): bool
|
||
|
|
{
|
||
|
|
return $this->approval_status === 'approved';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function isRejected(): bool
|
||
|
|
{
|
||
|
|
return $this->approval_status === 'rejected';
|
||
|
|
}
|
||
|
|
|
||
|
|
public function approve(): void
|
||
|
|
{
|
||
|
|
$this->update(['approval_status' => 'approved']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function reject(): void
|
||
|
|
{
|
||
|
|
$this->update(['approval_status' => 'rejected']);
|
||
|
|
}
|
||
|
|
}
|