Php 拉威尔有什么严格的方法吗?

Php 拉威尔有什么严格的方法吗?,php,laravel,laravel-5.2,Php,Laravel,Laravel 5.2,Laravel中的whereHas方法使用MySQL中的EXISTS。问题是,例如,当指定品牌和文字时,它会使用所有有或没有品牌的项目,其中文字存在。。。但我需要的是,当品牌指定时,只需要那些有品牌和文字的。 $parts=AutoPart\Part::has('classifier')->with(['details','classifier','order','place'])->orderBy('id','desc') 将最后一个条件更改为 if ($text = $request-&g

Laravel中的whereHas方法使用MySQL中的
EXISTS
。问题是,例如,当指定品牌和文字时,它会使用所有有或没有品牌的项目,其中文字存在。。。但我需要的是,当品牌指定时,只需要那些有品牌和文字的。 $parts=AutoPart\Part::has('classifier')->with(['details','classifier','order','place'])->orderBy('id','desc')


将最后一个条件更改为

 if ($text = $request->get('text', FALSE)) {
    if (strlen($text) > 0) {

       // This will put a bracket around the whereHas and the OrWherehas
       $parts->where(function($q) use($text) {
           $q->whereHas('details', function($query) use($text) {
               $query->where('notes', 'LIKE', '%' . $text . '%');
           });

           $q->orWhereHas('classifier', function($query) use($text) {
               $query->where('name', 'LIKE', '%' . $text . '%');
           });
       });

   }
}
希望能有帮助

 if ($text = $request->get('text', FALSE)) {
    if (strlen($text) > 0) {

       // This will put a bracket around the whereHas and the OrWherehas
       $parts->where(function($q) use($text) {
           $q->whereHas('details', function($query) use($text) {
               $query->where('notes', 'LIKE', '%' . $text . '%');
           });

           $q->orWhereHas('classifier', function($query) use($text) {
               $query->where('name', 'LIKE', '%' . $text . '%');
           });
       });

   }
}