michaeldyrynda / laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models
MIT License
442 stars 46 forks source link

Converting uuid string to bytes #89

Closed andrewmclagan closed 3 years ago

andrewmclagan commented 4 years ago

Is there a public method available for converting a uuid or array of uuids into bytes?

for example an app could create a bunch of posts with uuid on the client side:

[
    { uuid: '40b5a3ab-0154-4543-a442-f987c50a463d', title: 'Test post 1' },
    { uuid: '9128d630-2629-4f42-b038-1d9d0e8124df', title: 'Test post 2' },
    { uuid: '9ba7002b-4a68-41a3-a5b0-041c250e234a', title: 'Test post 3' },
]

How does one covert those to bytes? Some may exist in the DB others may not, need a way to do

->whereIn('uuid', $uuids) ->whereNotIn('uuid', $uuids)

etc...

All the current methods rely on a model instance which of course one may never have. Is that not the point of UUIDs? That client side can create the id?

A helper could be useful, Uuid::toBytes($uuids); Or Uuid::fromBytes($uuids)

michaeldyrynda commented 4 years ago

I've not tested it, but does the custom cast from the laravel-efficient-uuid package not handle this automatically?