我正在与 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);
}
书籍/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() }}