Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
72
app/Models/ImageAttachment.php
Normal file
72
app/Models/ImageAttachment.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BumpsContentVersion;
|
||||
use App\Models\Concerns\HasImages;
|
||||
use Database\Factories\ImageAttachmentFactory;
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* One image in a record's gallery.
|
||||
*
|
||||
* Carries what a gallery needs and a single cover never did: an order, a
|
||||
* description, and a caption — which is a different thing from a description.
|
||||
* The alt text is for whoever cannot see the image; the caption is shown to
|
||||
* everybody, and is where "before" and "after" belong.
|
||||
*/
|
||||
#[Fillable(['collection', 'path', 'alt', 'caption', 'position'])]
|
||||
class ImageAttachment extends Model
|
||||
{
|
||||
/** @use HasFactory<ImageAttachmentFactory> */
|
||||
use BumpsContentVersion, HasFactory, HasImages, HasTranslations;
|
||||
|
||||
/** @var array<int, string> */
|
||||
public array $translatable = ['alt', 'caption'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['position' => 'integer'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function imageAttributes(): array
|
||||
{
|
||||
return ['path'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphTo<Model, $this>
|
||||
*/
|
||||
public function attachable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BelongsTo<Media, $this>
|
||||
*/
|
||||
public function media(): BelongsTo
|
||||
{
|
||||
return $this->imageRelation('path');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<$this> $query
|
||||
* @return Builder<$this>
|
||||
*/
|
||||
public function scopeOrdered(Builder $query): Builder
|
||||
{
|
||||
return $query->orderBy('position')->orderBy('id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user