inhaus-plugin-chat/src/Models/Gif.php
Friederich Loheide 2844452002 Nachrichten-Plugin 1.0.0: Direktnachrichten, Gruppen, Anhänge, GIFs, Emojis
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 16:34:53 +00:00

27 lines
927 B
PHP

<?php
namespace Inhaus\Plugins\Chat\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;
use Inhaus\Plugins\Chat\Gifs;
#[Fillable(['path', 'title', 'tags', 'width', 'height'])]
class Gif extends Model
{
protected $table = 'chat_gifs';
protected static function booted(): void
{
// Maße für die Vorschau im Chat merken; Datei beim Löschen mit entfernen
static::saving(function (Gif $gif): void {
if ($gif->isDirty('path') && $gif->path && Storage::disk(Gifs::DISK)->exists($gif->path)) {
$size = @getimagesize(Storage::disk(Gifs::DISK)->path($gif->path));
$gif->width = $size[0] ?? null;
$gif->height = $size[1] ?? null;
}
});
static::deleted(fn (Gif $gif) => Storage::disk(Gifs::DISK)->delete($gif->path));
}
}