2017-01-19 5 views
1

私はサードパーティを使用しています。私はここから入手:paginateとfindwhereを同じように使うには? (laravel 5.3)

public function displayList($year, $id = NULL) 
{ 
    $clauses = ['year' => $year]; 
    if(isset($id)) { 
     $clauses = array_merge($clauses, ['id' => $id]); 
    } 
    $query = Self::orderBy('programcode') 
       ->orderBy('accountcode') 
       ->findWhere($clauses) 
       ->paginate(1); 
    return $query; 
} 

実行すると、このようなエラーが存在する:Method paginate does not exist.ファイルリポジトリ内https://github.com/andersao/l5-repository

My機能は、このようなものです。

私は->findWhere($clauses)を削除してみます。できます。エラーはありません。

Findwhereと明らかにページ付けは、この問題に対する解決策はあり同時に

を実行することはできませんか?

答えて

2

->findWhere(...)はクエリwith ->get()を終了し、結果(雄弁なコレクション)を返します。

あなたがしようとしているのは、eloquent collection->paginate(...)メソッドを呼び出すことです。実際にはquery builderの方法です。

ソリューション

applyConditions

$query = Self::orderBy('programcode') 
      ->orderBy('accountcode') 
      ->applyConditions($clauses) 
      ->paginate(1); 

編集

さて、あなたは連鎖方式それをオフにすることはできませんので、そう->applyCondtions()はオブジェクトを返しません。これを試してみてください:このように

$query = Self::orderBy('programcode') 
    ->orderBy('accountcode'); 
$query->applyConditions($clauses); 
$query = $query->paginate(1); 
+0

は何の解決策続行しますか?ドキュメントには ' - > paginate(...)'があります。ここを見てください:https://github.com/andersao/l5-repository –

+0

@mosestoh私は解決策を見つけたと確信しています。答えを更新しました。 – devk

+0

エラーがあります: 'メンバー関数への呼び出しpaginate()on null' –

1

$list = $this->repository->scopeQuery(function($query) use ($filterColumns) { 

    return $query->where($filterColumns)->orderBy('created_at', 'DESC'); 

}); 

$list->paginate(10); 
関連する問題