PHP code example of laragrad / eloquent-model-pg-casts

1. Go to this page and download the library: Download laragrad/eloquent-model-pg-casts 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/ */

    

laragrad / eloquent-model-pg-casts example snippets


class TestGroup extends Model 
{
    use \Laragrad\Models\Concerns\PgTypeCastable;

    protected $casts = [
    	'test_ids' => 'pg_uuid_array',
    ];
}

>>> $m = new App\TestGroup();
>>> $m->title = 'First group';
>>> $m->test_ids = ['00000000-0000-0000-0000-000000000001','00000000-0000-0000-0000-000000000002'];
>>> $m->save();
>>> $m->refersh();
>>> $m
=> App\TestGroup {#3171
     id: 1,
     title: "First group",
     test_ids: "{00000000-0000-0000-0100-000000000001,00000000-0000-0000-0100-000000000002}",
   }
>>> $m->test_ids
=> [
     "00000000-0000-0000-0100-000000000001",
     "00000000-0000-0000-0100-000000000002",
   ]
>>> $m->toArray()
=> [
     "id" => 1,
     "title" => "First group",
     "test_ids" => [
       "00000000-0000-0000-0100-000000000001",
       "00000000-0000-0000-0100-000000000002",
     ],
   ]