@php // If a Collection or array was passed accidentally, pick the first item. if (isset($art) && (is_array($art) || $art instanceof Illuminate\Support\Collection || $art instanceof Illuminate\Database\Eloquent\Collection)) { $first = null; if (is_array($art)) { $first = reset($art); } elseif ($art instanceof Illuminate\Support\Collection || $art instanceof Illuminate\Database\Eloquent\Collection) { $first = $art->first(); } if ($first) { $art = $first; } } $title = trim((string) ($art->name ?? $art->title ?? 'Untitled artwork')); $author = trim((string) ($art->uname ?? $art->author_name ?? $art->author ?? 'Skinbase')); $category = trim((string) ($art->category_name ?? $art->category ?? 'General')); $license = trim((string) ($art->license ?? 'Standard')); $resolution = trim((string) ($art->resolution ?? ((isset($art->width, $art->height) && $art->width && $art->height) ? ($art->width . '×' . $art->height) : ''))); // Safe integer extractor: handle numeric, arrays, Collections, or relations $safeInt = function ($v, $fallback = 0) { if (is_numeric($v)) return (int) $v; if (is_array($v)) return count($v); if (is_object($v)) { // Eloquent Collections implement Countable and have count() if (method_exists($v, 'count')) return (int) $v->count(); if ($v instanceof Countable) return (int) count($v); } return (int) $fallback; }; $likes = $safeInt($art->likes ?? $art->favourites ?? 0); $downloads = $safeInt($art->downloads ?? $art->downloaded ?? 0); $img_src = (string) ($art->thumb ?? $art->thumbnail_url ?? '/images/placeholder.jpg'); $img_srcset = (string) ($art->thumb_srcset ?? $art->thumbnail_srcset ?? $img_src); $img_avif_srcset = (string) ($art->thumb_avif_srcset ?? $img_srcset); $img_webp_srcset = (string) ($art->thumb_webp_srcset ?? $img_srcset); // Width/height may be stored directly or as a related object; handle safely $resolveDimension = function ($val, $fallback) { if (is_numeric($val)) return (int) $val; if (is_array($val)) { $v = reset($val); return is_numeric($v) ? (int) $v : (int) $fallback; } if (is_object($val)) { if (method_exists($val, 'first')) { $f = $val->first(); if (is_object($f) && isset($f->width)) return (int) ($f->width ?: $fallback); if (is_object($f) && isset($f->height)) return (int) ($f->height ?: $fallback); } // Try numeric cast otherwise if (isset($val->width)) return (int) $val->width; if (isset($val->height)) return (int) $val->height; } return (int) $fallback; }; $img_width = max(1, $resolveDimension($art->width ?? null, 800)); $img_height = max(1, $resolveDimension($art->height ?? null, 600)); $contentUrl = $img_src; $cardUrl = (string) ($art->url ?? '#'); @endphp