doubijiao2094 2019-04-11 17:49
浏览 150

在Laravel中使用过滤搜索时,运算符和值组合非法

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);
    });
  }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)