2016-11-13 57 views
3

我傳遞我的數組$職位,以我的觀點,我tryng使用分頁,但我有錯誤:Laravel 5.2 - 方法鏈接不存在

Method links does not exist. (View: C:\xampp\htdocs\app\resources\views\search.blade.php)

控制器

$posts = Post::where('visible', 1) 
->where('expire_date', '>', $current)->where('delete', 0); 
$posts->paginate(1); 
$posts = $posts->get(); 
return view('search', compact('posts')); 

VIEW

<div class="pagination-bar text-center"> 
     {{ $posts->links() }} 
</div> 

回答

7

更改您的代碼這樣的:

$posts = Post::where('visible', 1) 
      ->where('expire_date', '>', $current) 
      ->where('delete', 0) 
      ->paginate(1); 

return view('search', compact('posts')); 

您的代碼不起作用,因爲你不paginate()結果保存到一個變量,像$posts = $posts->paginate(1);。此外,您不應在paginate()之後使用get()all()

+1

是!現在它工作!非常感謝你! –

+0

我遵循相同的方法,但仍然得到相同的錯誤,爲什麼這樣? –

+0

@PoojaKrishna我建議你開始你自己的問題,並顯示'dd($ data)'的結果。在這種情況下,我們將能夠爲您提供幫助。沒有看到代碼和數據轉儲是不可能的。 –

相關問題