What's the question? Sorry, don't get it.
Aug 11, 2020
8
Level 4
How to add the pagination on index
Using single thread list on index page with @include.
How to use pagination on index as single page is working good.
Index page is here
@extends('layouts.front')
@section('heading')
<a href="{{route('thread.create')}}" class="btn btn-success float-right">Create Thread</a><br>
@endsection
@section('content')
@include('layouts.partials.msg')
<h2>Threads</h2>
@include('thread.partials.thread-list')
@endsection
Single thread list is here thread.partials.thread-list
<div class="">
@forelse ($threads as $thread)
<div class="card my-2">
<div class="card-body">
<a href="{{route('thread.show', $thread->id)}}">
<h4 class="card-title">{{ $thread->subject }}</h4>
</a>
<p class="card-text">{{ str_limit($thread->thread,100) }}</p>
<p class="card-link">Posted by: <a href="{{route('user_profile',$thread->user->name)}}">{{$thread->user->name}}</a> {{$thread->created_at->diffForHumans()}}</p>
</div>
</div>
@empty
<h5>No threads there</h5>
@endforelse
{{ $threads->links() }}
</div>
Level 55
Hi @webfuelcode change your controller to
public function index()
{
$threads = Thread::orderBy('created_at', 'desc')->paginate(5);
return view( 'thread.index', compact('threads') );
}
also you can dump you data in thread.partials.thread-list
<div class="">
{{ dd($threads, $threads->links()) }}
@forelse ($threads as $thread)
to chek what you have on Home page
1 like
Please or to participate in this conversation.