@extends('layouts.site') @section('content')
{{-- Preserve all current filter state when using the search bar --}} @foreach(request('amenities', []) as $amenity) @endforeach

Filter Properties

{{-- Single unified filter form --}}
@php $amenityOptions = [ 'parking' => 'Parking', 'wifi' => 'WiFi', 'pool' => 'Pool', 'gym' => 'Gym', 'air conditioning'=> 'Air Conditioning', ]; @endphp @foreach($amenityOptions as $value => $label)
@endforeach
Reset Filters

@php $hasActiveFilters = collect(request()->except(['page', 'sort']))->filter(function($v) { return !empty($v) && $v !== 'all'; })->isNotEmpty(); @endphp {{ $hasActiveFilters ? 'Filtered Properties' : 'All Properties' }} ({{ $properties->total() }} found)

{{-- Sort — updates the hidden sort field in filterForm and re-submits --}}
Sort by:
@if($properties->isEmpty())

No properties found

Try adjusting your search or filter criteria

Clear all filters
@else
@foreach($properties as $property)
@php $imageUrl = asset('no-image.png'); // Default to no-image.png if (!empty($property->images) && is_array($property->images) && count($property->images) > 0) { $firstImage = ltrim($property->images[0], '/'); // Check if it's already a full URL if (filter_var($firstImage, FILTER_VALIDATE_URL)) { $imageUrl = $firstImage; } else { $imageUrl = asset('storage/' . $firstImage); } } @endphp {{ $property->name }} @if($property->is_featured) Featured @endif {{ ucfirst(str_replace('_', ' ', $property->status)) }} @if(!empty($property->images) && is_array($property->images) && count($property->images) > 1) {{ count($property->images) }} @endif

{{ $property->name }}

{{ $property->address }}

{{ match($property->property_type) { 'single_house' => '🏠 Single House', 'apartment' => '🏢 Apartment', 'commercial' => '🏭 Commercial', 'mixed_use' => '🏬 Mixed Use', default => ucfirst(str_replace('_', ' ', $property->property_type)) } }}
@if($property->units->count() > 0) {{ $property->units->count() }} unit{{ $property->units->count() > 1 ? 's' : '' }} @php $vacantCount = $property->units->where('status', 'vacant')->count(); @endphp @if($vacantCount > 0) {{ $vacantCount }} available @endif @if($property->property_type != 'commercial') @php $unitBedrooms = $property->units->pluck('bedrooms')->filter(); $unitBathrooms = $property->units->pluck('bathrooms')->filter(); $minBeds = $unitBedrooms->min(); $maxBeds = $unitBedrooms->max(); $minBaths = $unitBathrooms->min(); $maxBaths = $unitBathrooms->max(); @endphp @if($minBeds) {{ $minBeds == $maxBeds ? $minBeds . ' bed' . ($minBeds > 1 ? 's' : '') : "$minBeds-$maxBeds beds" }} @endif @if($minBaths) {{ $minBaths == $maxBaths ? $minBaths . ' bath' . ($minBaths > 1 ? 's' : '') : "$minBaths-$maxBaths baths" }} @endif @endif @else @if($property->bedrooms) {{ $property->bedrooms }} bed{{ $property->bedrooms > 1 ? 's' : '' }} @endif @if($property->bathrooms) {{ $property->bathrooms }} bath{{ $property->bathrooms > 1 ? 's' : '' }} @endif @endif @if($property->square_footage) {{ number_format($property->square_footage) }} sqft @endif
@if($property->amenities && count($property->amenities) > 0)
@foreach(array_slice($property->amenities, 0, 3) as $amenity) {{ ucfirst($amenity) }} @endforeach @if(count($property->amenities) > 3) +{{ count($property->amenities) - 3 }} more @endif
@endif
@if($property->units->count() > 0) @php $unitRents = $property->units->pluck('rent_amount')->filter(); $minRent = $unitRents->min(); $maxRent = $unitRents->max(); @endphp @if($minRent && $maxRent) @if($minRent == $maxRent) UGX {{ number_format($minRent) }}/mo @else
Starting from UGX {{ number_format($minRent) }}/mo
@endif @else UGX {{ number_format($property->monthly_rent) }}/mo @endif @else UGX {{ number_format($property->monthly_rent) }}/mo @endif
View Details
@endforeach
{{ $properties->appends(request()->query())->links() }}
@endif
@push('scripts') @endpush @endsection