Files
ak 263b98b218 Initial baseline: LaraBlog core with plugin commerce surface.
Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
2026-08-12 01:15:38 +08:00

59 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use App\Domain\Media\AttachmentStorageService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Attachment extends Model
{
public const VISIBILITY_PUBLIC = 'public';
public const VISIBILITY_PRIVATE = 'private';
protected $fillable = [
'article_id',
'disk',
'path',
'thumb_path',
'filename',
'mime',
'size',
'checksum',
'visibility',
'legacy_filepath',
'synced_at',
'downloads',
];
protected function casts(): array
{
return [
'size' => 'integer',
'downloads' => 'integer',
'synced_at' => 'datetime',
];
}
public function article(): BelongsTo
{
return $this->belongsTo(Article::class);
}
protected static function booted(): void
{
static::deleting(function (Attachment $attachment): void {
app(AttachmentStorageService::class)->deleteFromDisk($attachment);
});
}
public function scopePubliclyVisible(Builder $query): Builder
{
return $query->where('visibility', self::VISIBILITY_PUBLIC);
}
}