27 lines
927 B
PHP
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));
|
|
}
|
|
}
|