Download the PHP package fereydooni/unixtime without Composer
On this page you can find all versions of the php package fereydooni/unixtime. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fereydooni/unixtime
More information about fereydooni/unixtime
Files in fereydooni/unixtime
Package unixtime
Short Description a Laravel package that automatically adds UNIX timestamp equivalents
License MIT
Informations about the package unixtime
Laravel UnixTime
Automatically keep Unix timestamp mirrors (e.g. created_at_unix) for every datetime column in your Laravel models. The package detects relevant columns, creates the _unix columns for you, keeps them in sync any time the model is saved/retrieved, and even rewrites orderBy, latest, and oldest calls so they transparently use the faster integer columns.
Why it exists: while building large datasets I found the ORM constantly ordering and filtering on datetime columns, which meant string comparisons or expensive casting. Integer indexes (
*_unix) make those same range/ordering queries consistently faster, so this package automates the boring part—adding, filling, and maintaining the mirrored integer fields.
Features
- 🔁 Keeps Unix timestamp equivalents in sync for all datetime/timestamp/date columns.
- ⚙️ Artisan command that scans your app, adds the missing
_unixcolumns, and can backfill legacy data. - 🧱 Schema Builder macros to add/drop Unix columns directly in migrations.
- 🔍 Smart auto-detection of datetime fields from the schema (casts are only a fallback).
- 🎛️ Per-model configuration for suffixes, explicit include/exclude lists, and helper methods like
getUnixTimestamp().
Installation
The service provider is auto-discovered, so no manual registration is required.
Quick Start
-
Use the trait on your model
-
Add the Unix columns
- Existing tables: run the sync command (see below).
- New migrations: call
$table->timestampEquivalents();at the end of the migration.
- Enjoy the new attributes
Adding Columns for Existing Tables
Use the included Artisan command to scan all models that use the trait and create any missing _unix columns.
Common options:
| Option | Description |
|---|---|
--model="App\\Models\\Customer" |
Limit the sync to one or more fully-qualified models (option may be repeated). |
--dry-run |
Show the pending changes without touching the database. |
--backfill |
After adding the columns, backfill existing rows using the database’s native Unix conversion functions. |
Example (specific model with backfill):
Adding Columns in New Migrations
The service provider registers Schema Builder macros so you can add Unix columns directly in migrations.
Need only one column?
Cleanup helper:
Model Configuration
Everything works out-of-the-box, but you can fine-tune behavior with optional properties:
Helper methods:
Query Builder Enhancements
The trait swaps in a custom Eloquent builder so ordering helpers automatically use the _unix columns whenever they exist. This keeps your queries fast without changing call sites.
Testing
Run the package test suite from your app:
License
The Laravel UnixTime package is open-sourced software licensed under the MIT license.