In my Laravel application, I am trying to use uuid as primary key in my database table, and I am using Str helper to generate a new uuid for each new line.
$table->uuid('id')->primary()->default(Str::uuid());
It works for the first line, but if I try to add another line it generates the same string, so it throw the Integrity constraint violation.
My code in the controller:
public function create(Request $request) {
$category = new category();
$category->name = $request->input('name');
$category->description = $request->input('description');
$category->save();
return redirect()->route('categoriesToAdmin');
}
Any solution for that ?
And what do you recommend me to use as PK ; UUID or incremented number ?