whereDate('created_at', $date) looks clean, but on a big table it quietly drops your index and does a full scan.
The Problem
Say you want notifications created on a specific day. The obvious call:
UserNotification :: query () -> whereDate ( 'created_at' , '2026-04-23' ) -> get ();
Laravel generates this SQL:
SELECT * FROM user_notifications WHERE DATE ( created_at ) = '2026-04-23'
See DATE(created_at) ? MySQL has to compute that function for every row before comparing. Your created_at index is useless, EXPLAIN shows a full table scan:
+----+-------------+--------------------+------+---------+ | id | select_type | table | type | rows | +----+-------------+--------------------+------+---------+ | 1 | SIMPLE | user_notifications | ALL | 5000000 | +----+-------------+--------------------+------+---------+
On 5k rows you won't notice.…