I have a search filter which is built via angular, and hits a Laravel API endpoint.
I'm submitting some fields, while leaving some blank and I get the following error.
Illegal operator and value combination.
This is my laravel code
public static function apply(Request $filters)
{
$property = (new Property)->newQuery();
if($filters->has('county')) {
$property->where('county', $filters->input('county'));
}
if($filters->has('town')) {
$property->where('town', $filters->input('town'));
}
if($filters->has('property_type')) {
$property->where('property_type', $filters->input('property_type'));
}
if($filters->has('selling_type')) {
$property->where('selling_type', $filters->input('selling_type'));
}
// Price
if($filters->has('min_price')) {
$property->where('price', '>=', $filters->input('min_price'));
}
if($filters->has('max_price')) {
$property->where('price', '<=', $filters->input('max_price'));
}
//Bedrooms
if($filters->has('min_bedrooms')) {
$property->where('bedrooms', '>=', $filters->input('min_bedrooms'));
}
if($filters->has('max_bedrooms')) {
$property->where('bedrooms', '<=', $filters->input('max_bedrooms'));
}
//Bathrooms
if($filters->has('min_bathrooms')) {
$property->where('bathrooms', '>=', $filters->input('min_bathrooms'));
}
if($filters->has('max_bathrooms')) {
$property->where('bathrooms', '<=', $filters->input('max_bathrooms'));
}
//Size
if($filters->has('min_size')) {
$property->where('size', '>=', $filters->input('min_size'));
}
if($filters->has('max_size')) {
$property->where('size', '<=', $filters->input('max_size'));
}
return $property->with('photos')->get();
}
This is then called by a function in a controller.
This is my angular component code. When the user hits search on the form, they hit the submit function.
Any idea why I'm getting this issue?
createSearchForm() {
this.searchForm = this.formBuilder.group({
county: ['', Validators.nullValidator],
town: ['', Validators.nullValidator],
min_bedrooms: ['', Validators.nullValidator],
max_bedrooms: ['', Validators.nullValidator],
min_bathrooms: ['', Validators.nullValidator],
max_bathrooms: ['', Validators.nullValidator],
min_price: ['', Validators.nullValidator],
max_price: ['', Validators.nullValidator],
selling_type: ['', Validators.nullValidator],
property_type: ['', Validators.nullValidator],
});
}
search() {
this.searchParams = (Object.assign({}, this.searchForm.value));
this.advertService.propertySearch(this.searchParams).subscribe(data => {
this.properties = data;
this.properties.forEach(property => {
if (property.photos) {
property.mainPhotoUrl = property.photos['url'];
console.log(property.mainPhotoUrl);
}
});
console.log(this.properties);
}, error => {
console.log(error);
});
}