Php Laravel 5.1查询范围

Php Laravel 5.1查询范围,php,mysql,laravel,scope,Php,Mysql,Laravel,Scope,这是我的范围代码: public function scopeTest($query, $text, $usrId) { if (trim($text) != "") { return $query->where("usrid", "=" ,"$usrId")->where("text1", "LIKE" ,"%$text%")->orWhere("text2", "LIKE" ,"%$text%"); }else{ return

这是我的范围代码:

public function scopeTest($query, $text, $usrId)
{
    if (trim($text) != "") {
        return $query->where("usrid", "=" ,"$usrId")->where("text1", "LIKE" ,"%$text%")->orWhere("text2", "LIKE" ,"%$text%");
    }else{
        return $query->where("usrid", "=" ,"$usrId");
    }
}
我无法生成此查询:

select * from table where usrid = $usrId and (text1 like '%$text%' or text2 like '%$text%');
因为或条件不能正常工作。

$query->where'usrid',$usrid->where函数$query使用$text{ $like=%{$text}%; $query->where'text1',LIKE',$LIKE->or where'text2',LIKE',$LIKE; };
别忘了在作用域中引入$text变量。虽然这是你的帖子,但我没有找到你上次编辑的令人信服的理由。当时我觉得这很无礼,所以投了反对票。