#Not pulling from db

16 messages · Page 1 of 1 (latest)

gleaming bronze
#

try to check for $hidden and scopes

peak willow
#

Well it’s difficult to help without seeing code. Check the actual SQL query being generated using something like Telescope or laravel-debugbar

vestal crown
#

This is queries in my debug bar, the top line is so that properties listed as 'Venues' do not appear on this page, but it's only displaying 1 of the 3 properties not listed as venues

peak willow
#

So again, show code. As looking at the queries, you’re clearly not doing a simple Property::get(). You’ve got a boat-load of clauses there.

vestal crown
#

The code showing where 0 = 1 is: $not_available_property_ids = PropertyDates::whereIn('date', $days)->where('status', 'Not available')->distinct()->pluck('property_id'); it looks to me like it's parameters to not show properties rather than to show them so I don't think it's this? I will paste my index function now

winged briar
#

its hard to read, please refer to #rules on formatting

vestal crown
#
        $data['lat'] = -34.3681325;
        $data['long'] = 18.8223162;

        $data['location'] = 'Accommodation';
        $data['checkin'] = $request->input('checkin');
        $data['checkout'] = $request->input('checkout');
        $data['guest'] = $request->input('guest');
        $data['bedrooms'] = $request->input('bedrooms');
        $data['beds'] = $request->input('beds');
        $data['bathrooms'] = $request->input('bathrooms');
        $data['min_price'] = $request->input('min_price');
        $data['max_price'] = $request->input('max_price');
 
        $data['space_type'] = SpaceType::all();
        $data['property_type'] = PropertyType::getAll()->where('status', 'Active')->pluck('name', 'id');
        $data['amenities'] = Amenities::where('status', 'Active')->get();
        $data['amenities_type'] = AmenityType::pluck('name', 'id');
        $data['property_type_selected'] = explode(',', $request->input('property_type'));
        $data['space_type_selected'] = explode(',', $request->input('space_type'));
        $data['amenities_selected'] = explode(',', $request->input('amenities'));
        $currency = Currency::getAll();
        if (Session::get('currency')) $data['currency_symbol'] = $currency->firstWhere('code', Session::get('currency'))->symbol;
        else $data['currency_symbol'] = $currency->firstWhere('default', 1)->symbol;
        $minPrice = Settings::getAll()->where('name', 'min_search_price')->first()->value;
        $maxPrice = Settings::getAll()->where('name', 'max_search_price')->first()->value;
        $data['default_min_price'] = $this->helper->convert_currency(Currency::getAll()->firstWhere('default')->code, '', $minPrice);
        $data['default_max_price'] = $this->helper->convert_currency(Currency::getAll()->firstWhere('default')->code, '', $maxPrice);
        if (!$data['min_price']) {
            $data['min_price'] = $data['default_min_price'];
            $data['max_price'] = $data['default_max_price'];
        }
#
 $data['date_format'] = Settings::getAll()->firstWhere('name', 'date_format_type')->value;
        return view('search.view', $data);
    }
```  end of index function, could not fit it in
peak willow
#

What are these getAll static methods?

vestal crown
#

Sorry I've changed this line I made it all() just to check something. php $data['space_type'] = SpaceType::getAll()->where('status', 'Active')->where('name', '!=','Venue')->pluck('name', 'id'); That is just the assignment and then I have a searchRseult function. I wanted to show you the index incase you could see an error there. The searchResult function: ```php
$full_address = $request->input('location');
$checkin = $request->input('checkin');
$checkout = $request->input('checkout');
$guest = $request->input('guest');
$bedrooms = $request->input('bedrooms');
$beds = $request->input('beds');
$bathrooms = $request->input('bathrooms');
$property_type = $request->input('property_type');
$space_type = $request->input('space_type');
$amenities = $request->input('amenities');
$book_type = $request->input('book_type');
$map_details = $request->input('map_details');
$min_price = $request->input('min_price');
$max_price = $request->input('max_price');
if (!is_array($property_type)) {
if ($property_type != '') {
$property_type = explode(',', $property_type);
} else {
$property_type = [];
}
}
if (!is_array($space_type)) {
if ($space_type != '') {
$space_type = explode(',', $space_type);
} else {
$space_type = SpaceType::select('id')->where('status', 'Active')->where('name','!=','Venue')->get()->toArray();
}
}
if (!is_array($book_type)) {
if ($book_type != '') {
$book_type = explode(',', $book_type);
} else {
$book_type = [];
}
}
if (!is_array($amenities)) {
if ($amenities != '') {
$amenities = explode(',', $amenities);
} else {
$amenities = [];
}
}

$property_type_val = [];
$properties_whereIn = [];
$space_type_val = [];
```

#
  $users_where['users.status'] = 'Active';

        $checkin = date('Y-m-d', strtotime($checkin));
        $checkout = date('Y-m-d', strtotime($checkout));

        $days = $this->helper->get_days($checkin, $checkout);
        unset($days[count($days) - 1]);

        $calendar_where['date'] = $days;

        $not_available_property_ids = PropertyDates::whereIn('date', $days)->where('status', 'Not available')->distinct()->pluck('property_id');
        $properties_where['properties.accommodates'] = $guest;

        $properties_where['properties.status'] = 'Listed';

        $property_approval = Settings::where('name', 'property_approval')->first()->value;
        $property_approval === 'Yes' ? ($properties_where['properties.is_verified'] = 'Approved') : '';
if (count($space_type)) {
            foreach ($space_type as $space_value) {
                array_push($space_type_val, $space_value);
            }
            $properties_whereIn['properties.space_type'] = $space_type_val;
        }

        if (count($property_type)) {
            foreach ($property_type as $property_value) {
                array_push($property_type_val, $property_value);
            }

            $properties_whereIn['properties.property_type'] = $property_type_val;
        }

        $currency_rate = Currency::getAll()
            ->firstWhere('code', \Session::get('currency'))
            ->rate;

        $properties = Properties::with([
            'property_address',
            'property_price',
            'users'
        ])
#
 ->whereHas('property_price', function ($query) use ($min_price, $max_price, $currency_rate) {
                $query->join('currency', 'currency.code', '=', 'property_price.currency_code');
                $query->whereRaw('((price / currency.rate) * ' . $currency_rate . ') >= ' . $min_price . ' and ((price / currency.rate) * ' . $currency_rate . ') <= ' . $max_price);
            })
            ->whereHas('users', function ($query) use ($users_where) {
                $query->where($users_where);
            })
            ->whereNotIn('id', $not_available_property_ids);

        if ($properties_where) {
            foreach ($properties_where as $row => $value) {
                if ($row == 'properties.accommodates' || $row == 'properties.bathrooms' || $row == 'properties.bedrooms' || $row == 'properties.beds') {
                    $operator = '>=';
                } else {
                    $operator = '=';
                }

                if ($value == '') {
                    $value = 0;
                }

                $properties = $properties->where(function ($query) use ($row, $operator, $value) {
                              $query->where($row, $operator, $value);
                              $query->orWhereNull('properties.is_verified');
                              });
            }
        }
if ($properties_whereIn) {
            foreach ($properties_whereIn as $row_properties_whereIn => $value_properties_whereIn) {
                $properties = $properties->whereIn($row_properties_whereIn, array_values($value_properties_whereIn));
            }
        }

        $properties = $properties->paginate(Session::get('row_per_page'))->toJson();
        echo $properties;
    }
#

Sorry for all the code

vestal crown
#

I think it's to do with this line not pulling the properties with a ''space_type'' != 'Venue' php $data['space_type'] = SpaceType::getAll()->where('status', 'Active')->where('name', '!=','Venue')->pluck('name', 'id');

winged briar
#

no idea what does getAll() means, but believe that you should able to check the queries were executed with the correct conditions in the debugbar