PHP code example of sunaoka / laravel-postgres-extension

1. Go to this page and download the library: Download sunaoka/laravel-postgres-extension 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/ */

    

sunaoka / laravel-postgres-extension example snippets




namespace App\Models;

class SomeModel extends \Sunaoka\LaravelPostgres\Eloquent\Model
{
    protected $casts = [
        'term' => \Sunaoka\LaravelPostgres\Eloquent\Casts\TsRangeCast::class, // tsrange
    ];
}

$some = SomeModel::whereId(1)
    ->returning(['*'])
    ->update([
        'term' => new TsRange('2020-09-01 00:00:00', '2020-09-01 23:59:59'),
    ]);

echo get_class($some);
// => Illuminate\Database\Eloquent\Collection

echo get_class($some->first());
// => App\Models\SomeModel
bash
php artisan vendor:publish --tag=postgres-extension
sql
update "some_models" 
set "term" = '[2020-09-01 00:00:00,2020-09-01 23:59:59)' 
where "id" = '1' 
returning *