PHP code example of vusys / laravel-bitemporal

1. Go to this page and download the library: Download vusys/laravel-bitemporal library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vusys / laravel-bitemporal example snippets


$product->prices()->correct(attributes: ['amount' => 12.00], validFrom: '2026-02-01');

use Vusys\Bitemporal\Concerns\HasBitemporalRelations;
use Vusys\Bitemporal\Relations\BitemporalMany;

class Product extends Model
{
    use HasBitemporalRelations;

    public function prices(): BitemporalMany
    {
        return $this->bitemporalMany(ProductPrice::class);
    }
}

use Vusys\Bitemporal\Bitemporal;

class ProductPrice extends Model
{
    use Bitemporal;

    protected string $temporalEntity = Product::class;
}

Schema::create('product_prices', function (Blueprint $table) {
    $table->id();
    $table->bitemporalForeignFor(Product::class);
    $table->decimal('amount', 10, 2);
    $table->bitemporalPeriods();
    $table->timestamps();
    $table->preventBitemporalOverlaps(['product_id']);
});

$price = $product->prices()
    ->validAt($invoice->issued_at)     // true on this business date
    ->knownAt($invoice->created_at)    // as we believed it then
    ->sole();

$product->prices()->changeEffectiveFrom(['amount' => 12.00], validFrom: '2026-06-01');
$product->prices()->correct(['amount' => 12.00], validFrom: '2026-02-01', validTo: '2026-03-01');
$product->prices()->retract(validFrom: '2026-02-01', validTo: '2026-03-01');