Ad
Laravel Eloquent Paginate Doesn't Exist Error
I'm trying to set pagination in a Laravel blade/view but it's showing an error with this message below:
BadMethodCallException
Method Illuminate\Database\Eloquent\Collection::paginate does not exist.
Controller
public function view()
{
$user = Auth::user();
$basic_info = User::find($user->id)->basic_info;
$category = Category::all()->paginate(10);
return view('admin.article.category-view')->with(['user' => $user, 'basic_info' => $basic_info, 'category' => $category]);
}
View Blade (admin.article.category-view)
<div class="panel-body">
<table class="table table-hover">
<thead>
<tr>
<th>Category Name</th>
</tr>
</thead>
<tbody>
@foreach($category as $cat)
<tr>
<td>{{ $cat->name }}</td>
</tr>
@endforeach
</tbody>
</table>
{{ $category->links() }}
</div>
Ad
Answer
You need to remove all()
:
$category = Category::paginate(10);
When you're using all()
you get all the rows from the table and get a collection
You can only invoke "paginate"
on a Query
, not on a Collection
.
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad