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ÔƒÅþ"