error 500 fix

This commit is contained in:
2026-10-31 15:34:53 +01:00
parent f7edd64c8a
commit a888fe3695
4 changed files with 37 additions and 10 deletions
+1 -1
View File
@@ -60,6 +60,6 @@ class Product extends Model
public function getFormattedPriceAttribute(): string
{
return '€ '.number_format($this->base_price, 2, ',', '.');
return '€ '.number_format((float) ($this->base_price ?? 0), 2, ',', '.');
}
}
+32 -6
View File
@@ -217,6 +217,34 @@ class MakerWorldService
return Setting::get('makerworld_user');
}
/**
* Safely extract a normalized list of model items from diverse API response formats.
*
* @return array<int, array<string, mixed>>
*/
public function extractModelsList(mixed $data): array
{
if (! is_array($data)) {
return [];
}
if (isset($data['data']) && is_array($data['data'])) {
$data = $data['data'];
}
$list = $data['hits'] ?? $data['designs'] ?? $data['list'] ?? $data['items'] ?? null;
if (is_array($list)) {
return array_values(array_filter($list, fn ($item) => is_array($item)));
}
if (array_is_list($data)) {
return array_values(array_filter($data, fn ($item) => is_array($item)));
}
return [];
}
/**
* Fetch user's favorited models from MakerWorld.
*/
@@ -233,9 +261,7 @@ class MakerWorldService
]);
if ($response->successful()) {
$data = $response->json();
return $data['hits'] ?? $data['designs'] ?? $data['list'] ?? (is_array($data) ? $data : []);
return $this->extractModelsList($response->json());
}
} catch (\Throwable $e) {
Log::error('MakerWorld getFavorites error: '.$e->getMessage());
@@ -260,9 +286,7 @@ class MakerWorldService
]);
if ($response->successful()) {
$data = $response->json();
return $data['hits'] ?? $data['designs'] ?? $data['list'] ?? (is_array($data) ? $data : []);
return $this->extractModelsList($response->json());
}
} catch (\Throwable $e) {
Log::error('MakerWorld getPublished error: '.$e->getMessage());
@@ -289,11 +313,13 @@ class MakerWorldService
foreach ($data['hits'] as $contest) {
if (! empty($contest['designs']) && is_array($contest['designs'])) {
foreach ($contest['designs'] as $design) {
if (is_array($design) && ! empty($design['id'])) {
$allDesigns[$design['id']] = $design;
}
}
}
}
}
return array_slice(array_values($allDesigns), 0, $limit);
}
@@ -208,6 +208,7 @@
<!-- Products Grid -->
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
@foreach($models as $model)
@if(!is_array($model)) @continue @endif
@php
$mId = $model['id'] ?? 0;
$isAlreadyImported = in_array($mId, $importedIds);
@@ -366,7 +367,7 @@
<a href="{{ route('product.show', $product->slug) }}" target="_blank" class="p-1.5 text-slate-400 hover:text-white inline-block" title="Bekijk in webshop">
<i data-lucide="eye" class="w-4 h-4"></i>
</a>
<button type="button" @click="openImportModal({{ $product->makerworld_id }})" class="p-1.5 text-indigo-400 hover:text-indigo-300 inline-block" title="Bewerken / Opnieuw synchroniseren">
<button type="button" @click="openImportModal({{ (int) ($product->makerworld_id ?? 0) }})" class="p-1.5 text-indigo-400 hover:text-indigo-300 inline-block" title="Bewerken / Opnieuw synchroniseren">
<i data-lucide="edit" class="w-4 h-4"></i>
</button>
</td>
+1 -1
View File
@@ -94,7 +94,7 @@
<!-- Cart Button with Counter -->
@php
$cartItems = session('cart', []);
$cartItems = is_array(session('cart')) ? session('cart') : [];
$cartCount = array_sum(array_column($cartItems, 'quantity'));
@endphp
<a href="{{ route('cart.index') }}" class="relative p-2.5 rounded-xl border border-slate-200 bg-white hover:bg-slate-50 text-slate-700 transition flex items-center space-x-2 shadow-2xs group">