簡體   English   中英

在Laravel雄辯的whereHas方法中引用外部變量

[英]Refer to external variables in Laravel eloquent whereHas method

以下代碼給出錯誤Undefined variable searchParam 需要幫忙。

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

嘗試-

$results=Image::whereHas('subjects',function($q) use ($searchParam){
     $q->where('subject','LIKE','%'.$searchParam.'%');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM