PHPackages                             omaralalwi/laravel-time-craft - 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. [Database &amp; ORM](/categories/database)
4. /
5. omaralalwi/laravel-time-craft

ActiveLibrary[Database &amp; ORM](/categories/database)

omaralalwi/laravel-time-craft
=============================

Laravel Time Craft is a powerful package for handling date and time scopes in your Laravel applications. It provides a set of convenient traits and helper functions to simplify date and time operations.

1.0.2(1y ago)137883MITPHPPHP &gt;=7.4

Since Aug 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/omaralalwi/laravel-time-craft)[ Packagist](https://packagist.org/packages/omaralalwi/laravel-time-craft)[ Docs](https://github.com/omaralalwi/laravel-time-craft)[ RSS](/packages/omaralalwi-laravel-time-craft/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (6)Used By (0)

Laravel Time Craft
==================

[](#laravel-time-craft)

 [ ![Laravel Time Craft](https://raw.githubusercontent.com/omaralalwi/laravel-time-craft/master/public/images/laravel-time-craft.jpg) ](https://github.com/omaralalwi/laravel-time-craft)

[![Latest Version on Packagist](https://camo.githubusercontent.com/042c95b41ed6e81ddaee1790c873ba602121ed6cfed60ceb0747f09401756701/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f6d6172616c616c77692f6c61726176656c2d74696d652d63726166742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omaralalwi/laravel-time-craft)[![Total Downloads](https://camo.githubusercontent.com/92d08b363b149d48cd1fd79677795183b4d7bd224513bfee9e56ad398d2db088/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f6d6172616c616c77692f6c61726176656c2d74696d652d63726166742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/omaralalwi/laravel-time-craft)[![GitHub Issues](https://camo.githubusercontent.com/b96e1c8e75351ced98f63d23bcaa75c7f1146293f5fa2854c86898b5bc92ef1a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6f6d6172616c616c77692f6c61726176656c2d74696d652d63726166742e737667)](https://github.com/omaralalwi/laravel-time-craft/issues)[![GitHub Stars](https://camo.githubusercontent.com/0afad22c3e24e64d97935735a660dc6be52efe95a4440be483535d21c20244bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6f6d6172616c616c77692f6c61726176656c2d74696d652d63726166742e737667)](https://github.com/omaralalwi/laravel-time-craft/stargazers)[![License](https://camo.githubusercontent.com/ab1cbe5b17b4819f7f4e6064e44975ac27354e72e8691edb1a7f899b19cb4e25/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6f6d6172616c616c77692f6c61726176656c2d74696d652d63726166742e737667)](https://github.com/omaralalwi/laravel-time-craft/blob/main/LICENSE)

simple trait and helper functions that allow you, Effortlessly manage date and time queries in Laravel apps, with pre-built scopes and helper functions with ease.

Features
--------

[](#features)

- **Flexible Date Scopes**: Easily filter records based on various time frames (e.g., today, yesterday, current week, last month, etc.).
- **Helper Functions**: Utility functions for formatting dates, times, and human-readable date-time representations.
- **Dynamic Field Support**: Scopes can be applied to any date or time field in your models.

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

[](#installation)

You can install the package via Composer:

```
composer require omaralalwi/laravel-time-craft
```

publish the package's configuration file:

```
php artisan vendor:publish --tag=laravel-time-craft
```

Usage
-----

[](#usage)

### Using the `HasDateTimeScopes` Trait

[](#using-the-hasdatetimescopes-trait)

Add the `HasDateTimeScopes` trait to your Eloquent model:

```
use Omaralalwi\LaravelTimeCraft\Traits\HasDateTimeScopes;

class Order extends Model
{
    use HasDateTimeScopes;
}
```

#### Available Scopes in `HasDateTimeScopes` trait

[](#available-scopes-in-hasdatetimescopes-trait)

You can apply various scopes in your model queries. Below are the descriptions, usage examples, and corresponding outputs for each scope:

- **`today`** : Filters records created today.

    ```
    $todayOrders = Order::today()->get();
    ```
- **`yesterday`** : Filters records created yesterday.

    ```
    $yesterdayOrders = Order::yesterday()->get();
    ```
- **`oneWeekAgo`** : Filters records created in the last seven days.

    ```
    $lastSevenDaysOrders = Order::oneWeekAgo()->get();
    ```
- **`lastWeek`** : Filters records created in the last week.

    ```
    $lastWeekOrders = Order::lastWeek()->get();
    ```
- **`currentWeek`** : Filters records created in the current week.

    ```
    $currentWeekOrders = Order::currentWeek()->get();
    ```
- **`last7Days`** : Filters records created in the last 7 days.

    ```
    $last7DaysOrders = Order::last7Days()->get();
    ```
- **`last10Days`** : Filters records created in the last 10 days.

    ```
    $last10DaysOrders = Order::last10Days()->get();
    ```
- **`last14Days`** : Filters records created in the last 14 days.

    ```
    $last14DaysOrders = Order::last14Days()->get();
    ```
- **`last15Days`** : Filters records created in the last 15 days.

    ```
    $last15DaysOrders = Order::last15Days()->get();
    ```
- **`last21Days`** : Filters records created in the last 21 days.

    ```
    $last21DaysOrders = Order::last21Days()->get();
    ```
- **`last30Days`** : Filters records created in the last 30 days.

    ```
    $last30DaysOrders = Order::last30Days()->get();
    ```
- **`lastDays($days)`** : Filters records created in the last number of days specified.

    ```
    // Filters records created in the last 5 days
    $last5DaysOrders = Order::lastDays(null,5)->get(); // null mean take default field 'created_at' , or you can pass it 'created_at'
    // Filters records created in the last 12 days
    $last10DaysOrders = Order::lastDays(null,12)->get();
    ```
- **`oneMonthAgo`** : Filters records created in the last 30 days.

    ```
    $ordersLast30Days = Order::oneMonthAgo()->get();
    ```
- **`lastMonth`** : Filters records created last month.

    ```
    $lastMonthOrders = Order::lastMonth()->get();
    ```
- **`currentMonth`** : Filters records created in the current month.

    ```
    $thisMonthOrders = Order::currentMonth()->get();
    ```
- **`lastYear`** : Filters records created in the last year.

    ```
    $lastYearOrders = Order::lastYear()->get();
    ```
- **`oneYearAgo`** : Filters records created exactly one year ago.

    ```
    $oneYearAgoOrders = Order::oneYearAgo()->get();
    ```
- **`currentYear`** : Filters records created in the current year.

    ```
    $thisYearOrders = Order::currentYear()->get();
    ```
- **`betweenDates`** : Filters records within a specific date range.

    ```
    $ordersBetweenDates = Order::betweenDates('2024-01-01', '2024-01-31')->get();
    ```

---

### Customize Scoping field

[](#customize-scoping-field)

all scopes using `created_at` by default. You can override by three ways:-

**in config file as default for all models**

```
'default_field' => 'your_specific_field'
```

**customize it for every model** : by adding following line in model class:

```
class Order extends Model
{
    use HasDateTimeScopes;

    protected $dateField = 'updated_at';
}
```

**pass field name directly when using the scopes:**

```
$lastWeekOrders = Order::lastWeek('updated_at')->get();
```

---

### Format Date Time Using Helper Functions

[](#format-date-time-using-helper-functions)

You can use the provided helper functions in your application (in Blade files or in any class). Below are the descriptions, usage examples, and corresponding outputs for each helper function:

- **`formatDate`** : Formats a given date to "Y-m-d" format.

    ```
    $formattedDate = formatDate($order->created_at); // 2024-08-25
    ```
- **`formatTime`** : Formats a given time to "h:i:s A" format.

    ```
    $formattedTime = formatTime($order->created_at); // 10:38:12 PM
    ```
- **`getHumanDateTime`** : Formats the created\_at datetime to "Y-m-d H:i:s A" format.

    ```
    $humanDateTime = getHumanDateTime($order->created_at); // 2017-02-15 10:38:12 PM
    ```
- **`formatDateTime`** : Formats a given date and time to "Y-m-d H:i:s A" format.

    ```
    $formattedDateTime = formatDateTime($order->created_at); // 2017-02-15 10:38:12 PM
    ```
- **`formatTimeAgo`** : Gets a human-readable "time ago" format for a given date.

    ```
    $timeAgo = formatTimeAgo($order->created_at); // 2 days ago
    ```
- **`startOfDay`** : Gets the start of the day for a given date.

    ```
    $startOfDay = startOfDay($order->created_at); // 2024-08-23 00:00:00
    ```
- **`endOfDay`** : Gets the end of the day for a given date.

    ```
    $endOfDay = endOfDay($order->created_at); // 2024-08-23 23:59:59
    ```
- **`isWeekend`** : Checks if a given date is on the weekend.

    ```
    $isWeekend = isWeekend($order->created_at); // true or false
    ```
- **`addDays`** : Adds a specified number of days to a given date.

    ```
    $futureDate = addDays($order->created_at, 10); // 2024-09-02
    ```
- **`subtractDays`** : Subtracts a specified number of days from a given date.

    ```
    $pastDate = subtractDays($order->created_at, 10); // 2024-08-13
    ```

---

Helpful Packages
----------------

[](#helpful-packages)

You may be interested in our other packages:

- **[Gpdf](https://github.com/omaralalwi/Gpdf)** : PDF converter for php &amp; Laravel apps, support storing PDF files to S3.
- **[laravel-taxify](https://github.com/omaralalwi/laravel-taxify)** : simplify tax (VAT) calculations in laravel apps.
- **[laravel-deployer](https://github.com/omaralalwi/laravel-deployer)** : Streamlined deployment for Laravel and Node.js apps.
- **[laravel-trash-cleaner](https://github.com/omaralalwi/laravel-trash-cleaner)** : Cleans logs and debug files for logs and debugging packages.

---

Tests
-----

[](#tests)

tests will coming soon.

Contributing
------------

[](#contributing)

Contributions are welcome! Please read our [contributing guidelines](CONTRIBUTING.md) before submitting a pull request.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

---

📚 Helpful Open Source Packages
------------------------------

[](#-helpful-open-source-packages)

- [![lexi translate](https://raw.githubusercontent.com/omaralalwi/lexi-translate/master/public/images/lexi-translate-banner.jpg) **Lexi Translate** ](https://github.com/omaralalwi/lexi-translate) simplify managing translations for multilingual Eloquent models with power of morph relationships and caching .
- [![laravel Taxify](https://raw.githubusercontent.com/omaralalwi/Gpdf/master/public/images/gpdf-banner-bg.jpg) **Gpdf** ](https://github.com/omaralalwi/Gpdf) Open Source HTML to PDF converter for PHP &amp; Laravel Applications, supports Arabic content out-of-the-box and other languages..
- [![laravel Taxify](https://raw.githubusercontent.com/omaralalwi/laravel-taxify/master/public/images/taxify.jpg) **laravel Taxify** ](https://github.com/omaralalwi/laravel-taxify) Laravel Taxify provides a set of helper functions and classes to simplify tax (VAT) calculations within Laravel applications.
- [![laravel Deployer](https://raw.githubusercontent.com/omaralalwi/laravel-deployer/master/public/images/deployer.jpg) **laravel Deployer** ](https://github.com/omaralalwi/laravel-deployer) Streamlined Deployment for Laravel and Node.js apps, with Zero-Downtime and various environments and branches.
- [![laravel Trash Cleaner](https://raw.githubusercontent.com/omaralalwi/laravel-trash-cleaner/master/public/images/laravel-trash-cleaner.jpg) **laravel Trash Cleaner** ](https://github.com/omaralalwi/laravel-trash-cleaner)clean logs and debug files for debugging packages.
- [![Laravel Startkit](https://raw.githubusercontent.com/omaralalwi/laravel-startkit/master/public/screenshots/backend-rtl.png) **Laravel Startkit** ](https://github.com/omaralalwi/laravel-startkit) Laravel Admin Dashboard, Admin Template with Frontend Template, for scalable Laravel projects.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Total

3

Last Release

624d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/46733da79a34ff686b036a09af1dcc6d21054aee25a5e029500dc87d3c69ba89?d=identicon)[WatheqAlshowaiter](/maintainers/WatheqAlshowaiter)

![](https://www.gravatar.com/avatar/92882431481b621f6509ff259dd600e327c27fc77adcba4fcc7177659059c9a8?d=identicon)[omaralalwi](/maintainers/omaralalwi)

---

Top Contributors

[![omaralalwi](https://avatars.githubusercontent.com/u/25439498?v=4)](https://github.com/omaralalwi "omaralalwi (20 commits)")

---

Tags

carboncastingdatedate-scopesdatetimeeloquentfilterslaravellaravel-scopeslaravel-time-craftormqueriesscopestraitlaravelormeloquentlaravel-packagetraitdatetimequerycarbonfiltersscopescastingquerieslaravel-date-scopesmutatorsomaralalwilaravel-time-craftlaravel querieslaravel scopeslaravel time scopescommon laravel scopesdate-scopes

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/omaralalwi-laravel-time-craft/health.svg)

```
[![Health](https://phpackages.com/badges/omaralalwi-laravel-time-craft/health.svg)](https://phpackages.com/packages/omaralalwi-laravel-time-craft)
```

###  Alternatives

[cerbero/query-filters

Filter Laravel Eloquent models based on query parameters.

85282.6k](/packages/cerbero-query-filters)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)[sarfraznawaz2005/indexer

Laravel package to monitor SELECT queries and offer best possible INDEX fields.

562.7k](/packages/sarfraznawaz2005-indexer)

PHPackages © 2026

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