@nickywan123 your $threads doesn't look like a paginated result but a Collection instance. Can you show how you create $threads?
Apr 15, 2021
10
Level 6
Method Illuminate\Database\Eloquent\Collection::links does not exist
I implemented laravel scout(aglolia) for search indexing for my posts.
So in my index I have something like below:
<div class="col-md-8">
@forelse($threads as $thread)
<div class="card mb-3">
<div class="card-header">
<div class="level">
<h4 class="flex">
<img src="{{asset('/images/uploads/threads/images/'.($thread->image ?? 'default-post-img.png'))}}" height="60" width="60" alt="image">
<a href="{{$thread->path()}}" style="text-decoration: none;">{{$thread->title}}</a>
</h4>
<a href="{{$thread->path()}}">{{$thread->replies_count}} {{Str::plural('reply',$thread->replies_count)}}</a>
</div>
</div>
</div>
@empty
<p>There are no threads at the moment.</p>
@endforelse
{{ $threads->links() }}
Now, the search function works normally but I added pagination to my threads and tried using the search function but it doesn't work and says:
Method Illuminate\Database\Eloquent\Collection::links does not exist
how do I fix this if I want to use paginate?
Level 34
@nickywan123 It should be:
class SearchController extends Controller
{
public function search(Request $request){
$threads = Thread::search($request->input('search'))->paginate(10);
return view('threads.index',compact('threads'));
}
}
I already told you to change ->get() to ->paginate() on my 2nd reply.
Please or to participate in this conversation.