dongluan0020 2015-04-16 08:46
浏览 117
已采纳

请参阅Laravel eloquent whereHas方法中的外部变量

The following code gives the error Undefined variable searchParam. Need help.

if($searchParam!=null){
        $results=Image::whereHas('subjects',function($q){
            $q->where('subject','LIKE','%'.$searchParam.'%');
        });
  • 写回答

1条回答 默认 最新

  • douju1852 2015-04-16 08:51
    关注

    Try with -

    $results=Image::whereHas('subjects',function($q) use ($searchParam){
         $q->where('subject','LIKE','%'.$searchParam.'%');
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?