2016-11-02 30 views
0

我正在尝试使用laravel 5进行搜索。但是我无法使用LIKE获取对象。Laravel 5 Where Query

这是我的代码。

public function search(){ 
     $term = Input::get('search'); 

     $employees = Auth::user()->employees; 

     $results = $employees->where('name','LIKE', 'murat')->all(); 

     return $results; 
} 
+0

能告诉你一些记录,你会期待? –

回答

1

所有的关系也可以作为查询生成器,你可以添加到employees通过调用employees()方法,不断链的条件到查询检索进一步的限制。

所以,你的功能会像:

public function search(){ 
    $term = Input::get('search'); 

    $results = Auth::user()->employees()->where('name','LIKE', 'murat')->all(); 

    return $results; 
}