Laravel 4 - 如何从提前访问外部变量


Laravel 4 - How to access outside variables from an advance where

我的模型中有一个名为 Book 的范围方法。

public function scopeBookAuthor($query, $input = array()){
    if($input['book_author'] != ''){
        return $query->where(function ($query) {
                    $query->where('book_author_last_name', 'LIKE', "%".$input['book_author']."%")
                          ->orWhere('book_author_middle_name', 'LIKE', "%".$input['book_author']."%")
                          ->orWhere('book_author_first_name', 'LIKE', "%".$input['book_author']."%");
                });
    }
}

第 3 行的函数内部发生错误。 它说Undefined variable: input .

我试图将输入变量作为另一个参数包含在内,但它不起作用

return $query->where(function ($query, $input) {...

有没有办法做到这一点?提前谢谢。

有一个肮脏的黑客:

return $query->where(function ($query) use ($input){