public function testUuidToBinary()
 {
     $uuid = Uuid::uuid5(Uuid::NAMESPACE_OID, 1);
     $binary = UuidConverter::uuidToBinary($uuid->toString());
     $finalUuid = Uuid::fromBytes($binary);
     $this->assertSame($uuid->toString(), $finalUuid->toString());
 }
 /**
  * Mutator for uuid attribute
  *
  * @throw InvalidUuidFormatException
  * @return string
  */
 public function setUuidAttribute($value)
 {
     //If it's a instance of Uuid, convert to string
     if ($value instanceof Uuid) {
         $value = $value->toString();
     }
     //If the uuid is not valid
     if (!Uuid::isValid($value)) {
         throw new InvalidUuidFormatException('The format of the uuid ' . $value . ' is not valid');
     }
     $this->attributes['uuid'] = UuidConverter::uuidToBinary($value);
 }
 /**
  * Run seeder
  */
 public function run()
 {
     $users = [['uuid' => UuidConverter::uuidToBinary(Uuid::uuid5(Uuid::NAMESPACE_OID, 'user_1')->toString()), 'account_id' => 1, 'role' => User::OWNER_ROLE, 'activation_code' => null, 'firstname' => 'Maxime', 'lastname' => 'Beaudoin', 'email' => '*****@*****.**', 'password' => Hash::make('123123123'), 'reset_password_code' => null, 'timezone' => 'America/Toronto', 'activated_at' => Carbon::now()->subDays(15), 'created_at' => Carbon::now()->subDays(15), 'updated_at' => Carbon::now()->subDays(15)]];
     DB::table('users')->insert($users);
 }
 /**
  * Run seeder
  */
 public function run()
 {
     $accounts = [['uuid' => UuidConverter::uuidToBinary(Uuid::uuid5(Uuid::NAMESPACE_OID, 'account_1')->toString()), 'owner_id' => 1, 'custom_domain' => null, 'name' => 'Account 1', 'slug' => 'account', 'language' => 'en', 'timezone' => 'America/Toronto', 'created_at' => Carbon::now()->subDays(365)]];
     DB::table('accounts')->insert($accounts);
 }
 /**
  * Convert UUID string to binary
  *
  * @param string $uuid
  * @throw throw
  * @return string
  */
 protected function convertUuid($uuid)
 {
     //If the UUID is not valid, we assume the model is not found
     if (!Uuid::isValid($uuid)) {
         throw with(new ModelNotFoundException())->setEntity($this->model);
     }
     //Convert the UUID first
     $uuid = UuidConverter::uuidToBinary($uuid);
     return $uuid;
 }