Level 75
@temian1 is an another account of @kikismedia
@kikismedia Don't do that anymore!
please what am i doing wrong pagination isnt working and im not getting any error , next button isnt working
class PostsIndex extends Component
{
// use WithPagination;
use WithPagination;
public $status;
public $school;
public $filter;
public $search;
protected $queryString = [
'status',
'school',
'filter',
'search',
];
protected $listeners = ['queryStringUpdatedStatus'];
public function mount()
{
$this->status = request()->status ?? 'All';
}
public function updatingSchool()
{
$this->resetPage();
}
public function updatingFilter()
{
$this->resetPage();
}
public function updatingSearch()
{
$this->resetPage();
}
public function updatedFilter()
{
if ($this->filter === 'My Exp') {
if (! auth()->check()) {
return redirect()->route('login');
}
}
}
public function queryStringUpdatedStatus($newStatus)
{
$this->resetPage();
$this->status = $newStatus;
}
public function render()
{
$statuses = Status::all()->pluck('id', 'name');
$schools = School::all();
return view('livewire.posts-index', [
'posts' => Post::with('user', 'school', 'status')
->when($this->status && $this->status !== 'All', function ($query) use ($statuses) {
return $query->where('status_id', $statuses->get($this->status));
})->when($this->school && $this->school !== 'All Schools', function ($query) use ($schools) {
return $query->where('school_id', $schools->pluck('id', 'name')->get($this->school));
})->when($this->filter && $this->filter === 'Top Exp', function ($query) {
return $query->orderByDesc('votes_count');
})->when($this->filter && $this->filter === 'My Exp', function ($query) {
return $query->where('user_id', auth()->id());
})->when($this->filter && $this->filter === 'Spam Posts', function ($query) {
return $query->where('spam_reports', '>', 0)->orderByDesc('spam_reports');
})->when(strlen($this->search) >= 3, function ($query) {
return $query->where('body', 'like', '%'.$this->search.'%');
})
->addSelect(['voted_by_user' => Vote::select('id')
->where('user_id', auth()->id())
->whereColumn('post_id', 'posts.id')
])
->withCount('votes')
->withCount('comments')
->orderBy('id', 'desc')
->simplePaginate(10)
->withQueryString(),
'schools' => $schools,
]);
}
}
i remove use use WithPagination; its working now
Please or to participate in this conversation.