[英]Call to a member function links() on array in Laravel error
我當時在與Laravel合作,試圖對我的書頁進行分頁。 我收到此錯誤“在Laravel中的數組上調用成員函數links()”。 可能是重復項的錯誤,但我仍然不知道如何解決問題。
BookController提琴:
public function index()
{
$books = Book::simplePaginate(3)->all();
$authors = Author::all();
$genres = Genre::all();
return view('books.all')->withBooks($books)->withAuthors($authors)->withGenres($genres);
}
books / all.blade.php提琴
<table class="table table-hover">
<tr class="info">
<td>#</td>
<td>Name</td>
<td>Author</td>
<td><center>Visit</center></td>
</tr>
@foreach($books as $book)
<tr>
<td width="50px"><img width="50px" height="75px" src="{{ asset('images/' . $book->image) }}"></td>
<td width="50px">{{ $book->name }}</td>
<td width="50px">{{ $book->author->name }}</td>
<td width="50px"><center><a href="{{ url('books', $book->id) }}"><button class="btn btn-success">Visit</button></a></td>
</tr>
@endforeach
</table>
{{ $books->links() }}
只需從$ books變量中刪除-> all()方法即可。
$books = Book::paginate(10);
paginate()函數考慮從表中獲取所有內容,這是Book模型在此處獲取的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.