@php
$originalName = $product->name;
$foundImage = null;
$dirPath = public_path('images');
if (is_dir($dirPath)) {
$filesInFolder = scandir($dirPath);
$searchClean = strtolower(str_replace(' ', '', $originalName));
$words = explode(' ', strtolower(trim($originalName)));
foreach ($filesInFolder as $file) {
if ($file === '.' || $file === '..') continue;
$fileClean = strtolower(str_replace(' ', '', $file));
if (str_contains($fileClean, $searchClean)) {
$foundImage = asset('images/' . $file);
break;
}
if (isset($words[0], $words[1])) {
$twoWords = $words[0] . $words[1];
if (str_contains($fileClean, $twoWords)) {
$foundImage = asset('images/' . $file);
break;
}
}
if (count($words) >= 2) {
if (str_contains($fileClean, $words[0]) && str_contains($fileClean, $words[1])) {
$foundImage = asset('images/' . $file);
break;
}
}
}
}
$src = $foundImage ?? 'https://placehold.co/600x600/e8e8e8/111111?text=' . urlencode($originalName);
@endphp
{{ $product->category->name ?? 'Tanpa Kategori' }}
{{ $product->name }}
@php
$statusClass = match($product->stock_status) {
'low' => 'stock-low',
'over' => 'stock-over',
default => 'stock-ok',
};
@endphp
{{ $product->stock_status_label }}