@php // $section is available from the page renderer // Default values for section content $sectionTitle = $section->content['title'] ?? 'Featured Products'; $numberOfProducts = (int)($section->content['number_of_items'] ?? 4); $displayType = $section->content['display_type'] ?? 'featured'; // 'featured' or 'latest' $viewAllLink = $section->content['view_all_link'] ?? null; // e.g., '/products' $viewAllText = $section->content['view_all_text'] ?? 'View All Products'; // Fetch products from BusinessDirectory module try { $productsQuery = \Modules\BusinessDirectory\Entities\Product::query() ->where('status', 'published'); // Assuming 'published' is the status for active products if ($displayType === 'featured') { $productsQuery->where('is_featured', true); } $products = $productsQuery->with('company') // Eager load company if you display company name ->orderBy('created_at', 'desc') // Or a specific order field ->take($numberOfProducts) ->get(); } catch (\Throwable $e) { $products = collect(); \Illuminate\Support\Facades\Log::error("Error fetching products for landing page section: " . $e->getMessage()); } @endphp @if($products->isNotEmpty())

{{ $sectionTitle }}

@foreach($products as $product)
@if($product->images && !empty($product->images[0])) {{-- Assuming images[0] stores a path relative to public storage --}} {{ $product->name }} @else
No Image
@endif

{{ $product->name }}

${{ number_format($product->sale_price ?? $product->price, 2) }} @if($product->sale_price && $product->price > $product->sale_price) ${{ number_format($product->price, 2) }} @endif

{{-- Link to the product detail page (assuming a route exists in BusinessDirectory) --}} View Product
@endforeach
@if($viewAllLink) @endif
@endif