Laravel 5.1查询范围

this is my scope code:

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");
    }
}

I cant building this query:

select * from table where usrid = $usrId and (text1 like '%$text%' or text2 like '%$text%');

Because the "or" condition doesn't work correctly.

Use a closure to create a group:

$query->where('usrid', $usrId)->where(function ($query) use ($text) {
   $like = "%{$text}%";

   $query->where('text1', 'LIKE', $like)->orWhere('text2', 'LIKE' ,$like); 
});