sarahman/laravel-timestamp-boolean-fields

Deal with the fields whose timestamp value means their boolean status.

1.1.2 2023-10-24 12:00 UTC

This package is auto-updated.

Last update: 2024-03-24 12:54:28 UTC


README

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

Introduction

This library can be used in the scenarios when you want to understand the db boolean field value as not only its status but also the time when it becomes true.

Code Sample

<?php

namespace App;

use Sarahman\Database\Support\BooleanTimestampFieldManipulator;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use BooleanTimestampFieldManipulator;

    protected $fillable = ['title', 'description', 'is_active'];

    protected static $boolTimestampFields = ['is_active'];

    public static function boot()
    {
        parent::boot();

        /** This trait method call is required for laravel v4.*. */
        self::bootBooleanTimestampFieldManipulator();
    }
}

Installation

This trait is installed via Composer. To install, simply add to your composer.json file:

composer require sarahman/laravel-timestamp-boolean-fields:1.1.*

After installing, you would just use it in your eloquent/model class and define the timestamp-based boolean fields in the $boolTimestampFields property as well as in $fillable property.

If the project is developed in Laravel v4.*, then you need to call bootBooleanTimestampFieldManipulator() method in the boot() of the class.

<?php
...
    public static function boot()
    {
        parent::boot();

        self::bootBooleanTimestampFieldManipulator();
    }
...

Note: The timestamp-based field names must be prefixed by is_; and the field names without its is_ prefix will be appended in the model attributes with time_being_ prefix; i.e. is_active field name will appended in the model attributes as time_being_active name. The is_active field value will be boolean and time_being_active field value will the timestamp value.

Support

If you are having general issues with this package, feel free to contact me through Gmail.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request.

Contribution

If you're using this package, I'd love to hear your thoughts. Thanks! Please feel free to contribute in this library and send us pull requests.

License

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