【发布时间】:2017-04-28 12:36:14
【问题描述】:
我正在使用 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 是数组还是对象?
-
试试这个 $books=DB::table('books')->paginate(3);而不是 $books = Book::simplePaginate(3)->all();
-
没有任何效果
-
@MuhammadRizwan 应该是一个数组。
标签: php laravel laravel-paginate