EDIT
Actually after looking at your code some more this is the wrong way to go about it...you're only showing a single cat on a page then you don't need to get the videos by the relation and it's easier if you just do:
// controller
// could also use Cat::find($this->cat_id); or route model binding to make your life easier...
$cat = Cat::where('id', $this->cat_id)->first();
$videos = Video::where('cat_id', $this->cat_id)
->orderBy(function($query) {
if ($this->sortField === 'visits' || $this->sortField === 'recent') {
$q->orderBy($this->sortField, $sortDirection);
}
})
->paginate();
return view('livewire.cat-show', compact('cat', 'videos'));
Then there's no need to do $cat->first() and instead of accessing videos through $cat you just directly hit $videos
ORIGINAL POST
Well...you're not calling paginate() on the relationship in show for starters
function show()
{
$cat = Cat::where('id', $this->cat_id)
->with(['videos' => function ($q) use ($sortDirection) {
if ($this->sortField === 'visits' || $this->sortField === 'recent') {
$q->orderBy($this->sortField, $sortDirection);
}
$q->paginate();
}])
->get();
return view('livewire.cat-show', ['cat' => $cat]);
}
This should do the trick for you however I don't see where you're setting $sortDirection in this show call.
Because you're using a paginator you don't need to use withCount() as the paginator will have the total number of items.