Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel中使用雄辩的ORM,使用';非regexp';_Php_Mysql_Regex_Eloquent_Laravel 5.2 - Fatal编程技术网

Php 在Laravel中使用雄辩的ORM,使用';非regexp';

Php 在Laravel中使用雄辩的ORM,使用';非regexp';,php,mysql,regex,eloquent,laravel-5.2,Php,Mysql,Regex,Eloquent,Laravel 5.2,我处理的是按slug分类搜索,我想排除结尾包含破折号和数字的结果(比如:powerbank-1)。 我的问题是: $categories = Category::where('active_products', ">", 0) ->where('slug', 'LIKE', "%$search_term%") ->where('slug', 'not regexp', "/$search_term-[0-9]/") ->get(); 我的结果仍然

我处理的是按slug分类搜索,我想排除结尾包含破折号和数字的结果(比如:powerbank-1)。 我的问题是:

$categories = Category::where('active_products', ">", 0)
    ->where('slug', 'LIKE', "%$search_term%")
    ->where('slug', 'not regexp', "/$search_term-[0-9]/")
    ->get();
我的结果仍然包含不需要的结果,slug中有-1和-2个结尾:

{
  "query": "powerbank",
  "categories": [
  {
    "id": 18,
    "parent_id": 17,
    "lft": 108,
    "rgt": 109,
    "depth": 1,
    "name": "Powerbank",
    "description": null,
    "description2": null,
    "products": 43,
    "active_products": 38,
    "created_at": "2016-08-25 20:51:42",
    "updated_at": "2016-09-20 06:06:06",
    "slug": "powerbank"
  },
  {
    "id": 20,
    "parent_id": 19,
    "lft": 124,
    "rgt": 125,
    "depth": 1,
    "name": "Powerbank",
    "description": null,
    "description2": null,
    "products": 43,
    "active_products": 38,
    "created_at": "2016-08-25 20:51:43",
    "updated_at": "2016-09-20 06:06:06",
    "slug": "powerbank-1"
  },
  {
    "id": 22,
    "parent_id": 21,
    "lft": 136,
    "rgt": 137,
    "depth": 1,
    "name": "Powerbank",
    "description": null,
    "description2": null,
    "products": 43,
    "active_products": 38,
    "created_at": "2016-08-25 20:51:43",
    "updated_at": "2016-09-20 06:06:06",
    "slug": "powerbank-2"
  }]
}

发现问题原因:从正则表达式中删除斜杠,因此itt将:


->其中('slug','not regexp',“$search\u term-[0-9]”

找到了问题原因:从正则表达式中删除斜杠,因此itt将:

->其中('slug','not regexp',“$search\u term-[0-9]”