The issue described in the question occurs when there are multiple records with the same date and the pagination uses the offset parameter. In such cases, the database may evaluate the records in a different order, resulting in incorrect pagination.
To solve this issue, you can add an additional, unique orderBy clause to ensure there is no ambiguity in the search order. In this case, you can order by the id column in ascending order.
Here's the updated code:
$events = Event::where('course_id', $course->id)
->orderBy('date', 'ASC')
->orderBy('id', 'ASC')
->paginate(10);
By adding the orderBy('id', 'ASC') clause, you ensure that the records are ordered by the id column in ascending order, which guarantees a consistent order even when there are multiple records with the same date.
This solution should resolve the issue and ensure correct pagination.