Laravel查询构建不起作用,为什么?

Could someone explain me the reason why is this query not working? I am trying to create a query - where clients name, email or phone match the necessary criteria. However, it seems to work only with one criteria (name or email or phone), not with several ones. That way, I do not get the results needed and I am left with non- filtered list.

Using Laravel 4.1

$q = new Contract;
$q = $q->with(array('lsct' => function($q) {
    return $q->select(array('id', 'code'));
}, 'client' => function($q) {
    return $q->select(array('id', 'name', 'phone', 'email'));
}));

if(Input::has('search')) {
    $criterion = Input::get('search');
    $q = $q->where(function($q) use ($criterion) {
        $q->where('uid', 'like', '%' . $criterion . '%')->orWhere('car_number', 'like', '%' . $criterion . '%');
    })->orWhereHas('lsct', function($q) use($criterion) {
        $q->where('code', 'like', '%' . $criterion . '%');
    })->orWhereHas('client', function($q) use($criterion) {
        $q->where('name', 'like', '%' . $criterion . '%');
        // When i try to add condition below, this 'orWhereHas' not working at all
        // ->orWhere('phone', 'like', '%' . $criterion . '%')
        //->orWhere('latakko_id', 'like', '%' . $criterion . '%');
    });
}

Have you tried installing debugbar to show you exactly what your application is querying?

Here is the link for Laravel 4

This might give you some clues if you can actually see what is being queried.