michaeldyrynda / laravel-efficient-uuid

MIT License
304 stars 42 forks source link

how to generate a new Uuid using efficientUuid() #25

Closed jcherrabi closed 4 years ago

jcherrabi commented 4 years ago

Hello there, it is unclear to me on how to generate a new uuid for my test unit, can you please share an example?

   factory(App\User::class)->create([
        'id' => 1,
        'name' => 'Admin',
        'uuid' => efficientUuid('uuid'),
    ]);

gives an error??? thank you .

michaeldyrynda commented 4 years ago

You should be able to just set a valid UUID as a string, and the package will handle casting it properly if it's already set.

michaeldyrynda commented 4 years ago

I've added some extra handling and some tests around this, but essentially what you're after is:

factory(App\User::class)->create([
    'id' => 1,
    'name' => 'Admin',
    'uuid' => $this->faker->uuid,
]);

The EfficientUuid cast will handle the rest for you.