I am trying to generate a UUID (not as primary key, just generate one) with the laravel-uuid package. The docs are pretty straightforward, so according to the readme file a UUID should be generated just by calling $uuid = Uuid::generate();
, but it returns an empty object. (I also tried $uuid = Uuid::generate(1);
)
I followed the installation instructions as provided there (nothing out of the ordinary), the app doesn't throw any errors, so I guess everything is right.
Alternative packages for this are also welcome.
After laravel 5.6 a new helper was added to generate Universal Unique Identifiers (UUID)
use Illuminate\Support\Str;
return (string) Str::uuid();
return (string) Str::orderedUuid();
The methods return a Ramsey\Uuid\Uuid
object
The orderedUuid()
method will generate a timestamp first UUID for easier and more efficient database indexing.