@php
use App\Models\PageMetaTag;
$testimonials = PageMetaTag::where('type', 'home')
->where('key', 'like', 'testimonial_%')
->get()
->groupBy(function ($item) {
// Extract the testimonial number (e.g., "1" from "testimonial_1_name")
preg_match('/testimonial_(\d+)_/', $item->key, $matches);
return $matches[1] ?? 0;
})
->map(function ($group, $index) {
// Reconstruct the original keys with values
$result = [];
foreach ($group as $item) {
$result[$item->key] = $item->key_value;
}
return $result;
})
->toArray();
@endphp
@foreach($testimonials as $index => $testimonial)
@endforeach