horat1us/yii2-carbon-behavior

Yii2 Carbon Timestamps Behavior

Maintainers

👁 Horat1us

Package info

github.com/Horat1us/yii2-carbon-behavior

pkg:composer/horat1us/yii2-carbon-behavior

Statistics

Installs: 2 048

Dependents: 2

Suggesters: 0

Stars: 1

Open Issues: 1

1.3.0 2024-11-12 15:11 UTC

Requires

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 5bfe4e5e603dc4616e66341b70f90b2198b32a12

  • Alexander Letnikow <reclamme.woop@gmail.com>

This package is auto-updated.

Last update: 2026-06-12 18:27:56 UTC


README

👁 Test & Lint
👁 codecov

Behavior to generate timestamps (created_at, updated_at etc.) using Carbon instance.

Main purpose of using Carbon (instead of native time() function, implemented in \yii\behaviors\TimestampBehavior) is ability to mock this values without tricks (using Carbon::setTestNow()).

Used in real projects with MySQL and PostgreSQL.

Installation

Using packagist.org:

composer require horat1us/yii2-carbon-behavior:^1.3

Usage

To generate timestamps using Carbon

<?php

namespace App;

use Horat1us\Yii\CarbonBehavior;
use yii\db;

/**
* Class Record
 * @package App
 * 
 * @property string $created_at [timestamp]
 * @property string $updated_at [timestamp]
 */
class Record extends db\ActiveRecord
{
 public function behaviors(): array {
 return [
 'uuid' => [
 'class' => CarbonBehavior::class, 
 ], 
 ];
 }
}

in followed example created_at and updated_at attributes will be filled with date and time generated using Carbon class.

License

MIT