I have a UUID system on my application and when I register a user I have to indicate the rank_id, only I don't know its ID as it is generated from a UUID. So I use a query but it seems to me disgusting.
Do you have another solution? I thought about not putting a UUID on the rank table to make it easier but I don't know if it's a good idea to mix uuid and classic id
User::create([
'rank_id' => Rank::select('id')->where('title', 'User')->first()->id,
'username' => $request->input('username'),
'email' => strtolower($request->input('email')),
'password' => Hash::make($request->input('password')),
]);
Schema::create('users', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->foreignUuid('rank_id')->constrained('ranks');
$table->string('username');
$table->string('email');
$table->string('password');
$table->integer('status')->default(0);
$table->rememberToken();
$table->timestamps();
});
Schema::create('ranks', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('title');
$table->timestamps();
});