PHP code example of verbanent / eloquent-binary-uuid

1. Go to this page and download the library: Download verbanent/eloquent-binary-uuid 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/ */

    

verbanent / eloquent-binary-uuid example snippets


Schema::create('table_name', function (Blueprint $table) {
    $table->uuid('id');
});

Schema::create('table_name', function (Blueprint $table) {
    $table->uuid('uuid');
    $table->primary('uuid');
});

use Illuminate\Database\Eloquent\Model;
use Verbanent\Uuid\Traits\BinaryUuidSupportableTrait;

class Book extends Model
{
    use BinaryUuidSupportableTrait;
}

use Illuminate\Database\Eloquent\Model;
use Verbanent\Uuid\Traits\BinaryUuidSupportableTrait;

class Book extends Model
{
    use BinaryUuidSupportableTrait;

    public $uuidColumn = 'uuid';
}

use Verbanent\Uuid\AbstractModel;

class Lang extends AbstractModel
{
    //
}

use Verbanent\Uuid\AbstractModel;

class Lang extends AbstractModel
{
    public $uuidColumn = 'uuid';
    protected $primaryKey = 'uuid';
    protected $fillable = ['uuid'];
}

use Verbanent\Uuid\AbstractModel;
use Verbanent\Uuid\Traits\ForeignBinaryUuidSupportableTrait;

class LangTranslation extends AbstractModel
{
    use ForeignBinaryUuidSupportableTrait;

    private $uuidable = [
        'lang',
        'one_lang_bucket',
    ];
}

$book = new \App\Book;
$book->save();
dd($book->uuid());
// Output: "11e947f9-a1bd-f844-88d8-6030d483c5fe"

# If you use the default primary key:
dd($book->id);
// Output: b"\x11éGù¡½øDˆØ`0ÔƒÅþ"

# If you use `uuid` as a primary key:
dd($book->uuid);
// Output: b"\x11éGù¡½øDˆØ`0ÔƒÅþ"

$lang = Lang::find('11e947f9-a1bd-f844-88d8-6030d483c5fe');
dd($lang->uuid());
// Output: "11e947f9-a1bd-f844-88d8-6030d483c5fe"

$langTranslation = LangTranslation::findByUuid('lang', '11e947f9-a1bd-f844-88d8-6030d483c5fe');
dd($langTranslation[0]->uuid(), $langTranslation[1]->uuid(), $langTranslation[2]->uuid());
// Output: "11e94805-b94c-68e0-8720-6030d483c5fe"
//         "11e94805-b955-4e2e-b089-6030d483c5fe"
//         "11e94805-b957-af02-8bf8-6030d483c5fe"

$translation = LangTranslation::findByUuid('lang', '11e947f9-a1bd-f844-88d8-6030d483c5fe')->first();
dd($translation->foreignUuid('lang'));
// Output: "11e947f9-a1bd-f844-88d8-6030d483c5fe"

dd($translation->lang);
// Output: b"\x11éGù¡½øDˆØ`0ÔƒÅþ"