Laravel嵌套在哪里 解析错误:语法错误,意外的'}'



symfony component component debug 异常 fatalthrowableerror:parse错误:语法错误,意外'}'

我遵循此资源以嵌套在这里:如何将雄辩中的从句组合,但在运行代码时会遇到以下错误。打破的线路是回调功能的卷发括号,这里有什么问题?

$providers = DB::table('users')
->where('verified', '=', 1)
->where('status', '=', 1)
->where(function ($query) use ($search) {
    $query->where(DB::raw('lower(name)'), 'LIKE', "%".strtolower($search)."%")
    ->orWhere(DB::raw('lower(username)'), 'LIKE', "%".strtolower($search)."%")
})
->where('city', '=', $t)
->take($limit)
->toSql();

您在内部$query之后缺少;。我认为那部分可能是:

->where(function ($query) use ($search) {
    $query->where(DB::raw('lower(name)'), 'LIKE', "%".strtolower($search)."%")
    ->orWhere(DB::raw('lower(username)'), 'LIKE', "%".strtolower($search)."%");
})

代码最终需要该分号,因为它是函数中的行/语句。这个功能是回调的都不重要。

最新更新