PHPackages                             omar-elnaghy/laradate-filters - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. omar-elnaghy/laradate-filters

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

omar-elnaghy/laradate-filters
=============================

A Laravel package for advanced date filtering and manipulation

1.0.8(2y ago)1303.6k10[2 PRs](https://github.com/omarelnaghy/lara-date-filter/pulls)MITPHP

Since Sep 13Pushed 2y ago2 watchersCompare

[ Source](https://github.com/omarelnaghy/lara-date-filter)[ Packagist](https://packagist.org/packages/omar-elnaghy/laradate-filters)[ RSS](/packages/omar-elnaghy-laradate-filters/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (10)Used By (0)

Laravel Date Filtering Package
==============================

[](#laravel-date-filtering-package)

A Laravel package for advanced date filtering and manipulation

Laravel Date Filtering is a package that simplifies date-based filtering for your Laravel Eloquent models. It provides a set of convenient methods to filter records based on various date and time intervals.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require omar-elnaghy/laradate-filters
```

then publish config file

```
php artisan vendor:publish --provider="OmarElnaghy\LaraDateFilters\ServiceProvider"
```

Usage
-----

[](#usage)

Date Filtering Methods: Use the provided methods like FilterByDateRange, FilterByDateHoursRange, FilterByDateMinutesRange, etc., to filter records based on your specific criteria.

```
use Illuminate\Database\Eloquent\Model;
use OmarElnaghy\LaraDateFilters\Traits\Builder\PackageBuilder;

class YourModel extends Model
{
    public function newEloquentBuilder($query)
    {
        return new PackageBuilder($query);
    }
}
```

Features
--------

[](#features)

**Date Range Filtering** : You can filter records based on a specified date range, including records created "after" or "before" a certain date and time.

```
$startDate = Carbon::parse('2023-9-03');
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$direction = 'after';
$results = Post::filterByDateRange(2,'day',$startDate, $direction, $range)->get();
```

**Flexible Time Units** : You can filter records using various time units, such as seconds, minutes, hours, days, weeks, or months.

```
    $results = Post::filterByDateRange(2,'day',$startDate, $direction, $range)->get();
    $results = Post::filterByDateRange(2,'week',$startDate, $direction, $range)->get();
    $results = Post::filterByDateRange(2,'hour',$startDate, $direction, $range)->get();
```

**Inclusive or Exclusive Ranges** : You can choose whether the date range should be inclusive or exclusive, allowing you to fine-tune your query results.

```
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::EXCLUSIVE;
```

***The key feature***

The key feature of this trait is its ability to catch and handle dynamic date filtering methods based on a simple naming convention, making it incredibly convenient and powerful for developers:

Dynamic Date Filtering Magic

Unleash the magic of dynamic date filtering with our BuilderTrait! No more writing tedious, repetitive date filtering methods. With this trait, you can create date filters on the fly by simply following a naming convention.

```
    $results = Post::filterByDateSecondsRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateMinutesRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateHoursRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateDaysRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateWeeksRange(2,$startDate, $direction, $range)->get();

    $results = Post::filterByDateMonthsRange(2,$startDate, $direction, $range)->get();
```

Effortless Date Filtering

Imagine you want to filter records by date, but you don't want to write separate methods for every possible duration—seconds, minutes, hours, days, weeks, months, and more. Our BuilderTrait has you covered. Just name your method following the pattern "filterByDateXRange," and voila! X can be any duration, and the trait will handle the rest.

```
// [Duration] is a number refer to the number of [Date Unit] you want to search in
return Post::filterByDate(Duration)(Date Unit)Range($startDate, $direction, $range)->get();
```

Convenient and Flexible

Need to filter records for the last 30 minutes? Call filterByDate30MinutesRange(). Want records from the last week? It's as simple as filterByDate{duration}{unit}Range(). The trait dynamically generates these methods, making your code clean and your life easier.

Examples
--------

[](#examples)

1 - Filter by Custom duration and date unit (second,minutes,hours,..)

```
$startDate = Carbon::parse('2023-09-03');
$range = \OmarElnaghy\LaraDateFilters\Enums\DateRange::INCLUSIVE;
$direction = 'after';

return Post::filterByDate5DayRange($startDate, $direction, $range)->get();

return Post::filterByDate6WeekRange($startDate, $direction, $range)->get();

return Post::filterByDate7MonthRange($startDate, $direction, $range)->get();
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

9

Last Release

968d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd64e68075e0cd83e099553873c28243db93b4cf5252148da17eef54db38f40a?d=identicon)[omarelnaghy](/maintainers/omarelnaghy)

---

Top Contributors

[![omarelnaghy](https://avatars.githubusercontent.com/u/53927064?v=4)](https://github.com/omarelnaghy "omarelnaghy (23 commits)")[![kgrzelak](https://avatars.githubusercontent.com/u/51724541?v=4)](https://github.com/kgrzelak "kgrzelak (1 commits)")

### Embed Badge

![Health badge](/badges/omar-elnaghy-laradate-filters/health.svg)

```
[![Health](https://phpackages.com/badges/omar-elnaghy-laradate-filters/health.svg)](https://phpackages.com/packages/omar-elnaghy-laradate-filters)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
