У меня есть поисковый фильтр, построенный с помощью угловых точек и попадающий в конечную точку API Laravel.
Я отправляю некоторые поля, оставляя некоторые пустыми, и получаю следующую ошибку.
Недопустимая комбинация оператора и значения.
Это мой код Laravel
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();
}
Затем вызывается функцией в контроллере.
Это мой угловой компонентный код. Когда пользователь нажимает кнопку поиска в форме, он нажимает функцию отправки.
Есть идеи, почему я получаю эту проблему?
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);
});
}