Level 61
Besides breaking encapsulation and not doing strict comparison, it looks OK.
I want to send mentioned users to the reply when clicking on a notification.
The problem... replies are paginated and nested (one level like this forum).
I wrote this on the Reply model. It works...
public function isOnPageNum()
{
// root replies to count
$count = $this->replyable->replies()->whereNull('parent_id')->get('id')
// stop counting when when we reach the parent or this item
->takeUntil( fn($item) => $item->id == ($this->parent_id ?? $this->id))
->count();
return max((int) ceil(++$count / $this->perPage), 1);
}
Now from a Reply I can get its page, $reply->isOnPageNum()
And, create a correct url... ... /path-to-replyable?page=3#reply-557
Thoughts?
Please or to participate in this conversation.