🎉🎉 Larasense is officially launched 🎉🎉
- Your Hub for Laravel News, Trends & Updates

Laravel 11.42 Introduces New Date Query Methods

laravel
release
query
Nabil Hassen
Nabil Hassen
Feb 12, 2025
Laravel 11.42 Introduces New Date Query Methods
Last updated on Feb 12, 2025
Table of contents:

New Date Query Methods in Eloquent in 11.42

Laravel continues to enhance the developer experience with a new set of methods in the Query Builder, simplifying date-based queries. These methods, introduced in a recent pull request by Jason McCreary, provide more readable and intuitive ways to filter records based on dates.

New Methods for Date-Based Queries

The update introduces the following methods and more:

  • wherePast(): Retrieves records where a date column is in the past.
  • whereNowOrPast(): Fetches records where the date column is in the past or at the current moment.
  • orWherePast(): Adds an OR condition for past dates.
  • orWhereNowOrPast(): Adds an OR condition for past or present dates.
  • whereFuture(): Selects records where a date column is in the future.
  • whereNowOrFuture(): Finds records where the date column is in the future or at the current moment.
  • orWhereFuture(): Adds an OR condition for future dates.
  • orWhereNowOrFuture(): Adds an OR condition for future or present dates.

How These Methods Improve Queries

Previously, filtering records based on relative dates required verbose where conditions, such as:

$pastRecords = Model::where('date_column', '<', now())->get();

With the new methods, the same query becomes more readable:

$pastRecords = Model::wherePast('date_column')->get();

This improvement enhances both code clarity and maintainability.

Example Use Cases

Get All Expired Subscriptions

$expiredSubscriptions = Subscription::wherePast('expires_at')->get();

Find Events Happening Now or in the Future

$upcomingEvents = Event::whereNowOrFuture('event_date')->get();

Retrieve Orders Placed in the Past

$pastOrders = Order::wherePast('created_at')->get();

Availability

These methods are part of the latest Laravel 11.42 release. You can explore the full implementation in the Pull Request.

With these new date query methods, Laravel makes working with date-based data more intuitive, further improving the developer experience.

Nabil Hassen
Nabil Hassen
Full Stack Web Developer

Stay Updated.

I'll you email you as soon as new, fresh content is published.

Thanks for subscribing to my blog.

Latest Posts