update: lazily compute forum post permalink page number

This commit is contained in:
Roardom
2023-07-15 23:22:24 +00:00
parent 70471626f8
commit 9ba5c7e7c3
9 changed files with 25 additions and 46 deletions
+14
View File
@@ -365,4 +365,18 @@ class TopicController extends Controller
return to_route('topics.show', ['id' => $topic->id])
->withSuccess('This Topic Is Now Unpinned!');
}
/**
* Redirect to the appropriate topic page.
*/
public function permalink(int $topicId, int $postId): \Illuminate\Http\RedirectResponse
{
$index = Post::where('topic_id', '=', $topicId)->where('id', '<', $postId)->count();
return to_route('topics.show', [
'id' => $topicId,
'page' => intdiv($index, 25) + 1
])
->withFragment('post-'.$postId);
}
}