Laravel's Eloquent whereDate() filtering method

Laravel provides many additional methods other than standard methods. You might be familiar with where(), orWhere(), whereJsonContains() or whereJsonLength(). And these additional methods are worth checking.

In this article, we will see whereDate(), one of the supplementary method that comes handy when you want to compare the table’s field value with a specific date.

whereDate()

The whereDate() method helps to get records matching the specific date.

Example 1

$users = User::whereDate('birth_date', '2020-12-31')->get();

Example 2

$orders = Order::whereDate('created_at', '2021-01-19')->get();

Happy 😄 coding

With ❤️ from 🇮🇳

Vishnu Damwala
Vishnu Damwala

A web geek, an industry experienced web developer & tutor/instructor residing in India 🇮🇳