搜索数据库内容:laravel

时间:2017-05-02 09:30:33

标签: php

public function scopeSearchByKeyword($query, $keyword)
{
    if ($keyword!='') {
        $query->where(function ($query) use ($keyword) {
            $query->where("name", "LIKE","%$keyword%")
                ->orWhere("email", "LIKE", "%$keyword%")
                ->orWhere("blood_group", "LIKE", "%$keyword%")
                ->orWhere("phone", "LIKE", "%$keyword%");
        });
    }
    return $query;
}

'$ query'参数用于什么?函数($ query)使用($ keyword){}是什么意思?

$keyword = Input::get('keyword', '');
$users = User::SearchByKeyword($keyword)->get();

为什么它只是'SearchByKeyword'而不是scopeSearchByKeyword?

0 个答案:

没有答案