Description
What needs to be done?
Update the package so that when initializing a new project it:
- Generates a migration that adds an enum
role field (values: 'admin', 'user') to the users table instead of creating a role_id field and a relationship with the roles table.
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->enum('role', ['admin', 'user'])->nullable();
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('role');
});
}
2) Generates a RoleEnum enum class with values Admin = 'admin' and User= 'user' at the appropriate location App\Enums\User\RoleEnum.php
3) Generates the ClerkUserRepository class with role_id replaced by role
Before:
class ClerkUserRepository extends UserRepository
{
public function fromToken(Token $token): User
{
$user = parent::fromToken($token);
return User::firstOrCreate([
'clerk_id' => $user->getAuthIdentifier(),
], [
'role_id' => Role::USER,
]);
}
}
After:
class ClerkUserRepository extends UserRepository
{
public function fromToken(Token $token): User
{
$user = parent::fromToken($token);
return User::firstOrCreate([
'clerk_id' => $user->getAuthIdentifier(),
], [
'role' => RoleEnum::User,
]);
}
}
4) Update the add_default_user.php migration to use the new role enum field instead of role_id.
5) Implements logic (executed after generating the role field) that updates User.php using the helper package ronasit/larabuilder:
- Adds
'role' to the $fillable array. - Adds
$casts property with 'role' => RoleEnum::class mapping. - Imports
RoleEnum at the top of User.php via use App\Enums\User\RoleEnum;.
Expected outcome
What is the expected result?
Verification scenarios
How can this be tested?
- Run the init command and verify the generated migration creates the
role enum column with correct values and no role_id. - Confirm the generated
RoleEnum file exists and follows naming/location conventions. - Verify the generated
ClerkUserRepository::fromToken method assigns the role via enum value correctly and creates or finds the user by clerk_id. - Check the generated
User.php contains 'role' in $fillable, has the proper $casts entry, and imports the enum. - Run the generated project's migrations and verify the system functions normally with
roles handled via the enum field. - Test migration rollback works without errors in the generated project.
- Ensure no debug info or errors in application logs or console
Resources
Materials (Screenshots, Figma Links, References)
Description
What needs to be done?
Update the package so that when initializing a new project it:
rolefield (values: 'admin', 'user') to theuserstable instead of creating arole_idfield and a relationship with therolestable.2) Generates a
RoleEnumenum class with valuesAdmin = 'admin'andUser= 'user'at the appropriate locationApp\Enums\User\RoleEnum.php3) Generates the ClerkUserRepository class with
role_idreplaced byroleBefore:
After:
4) Update the
add_default_user.phpmigration to use the newroleenum field instead ofrole_id.5) Implements logic (executed after generating the
rolefield) that updatesUser.phpusing the helper packageronasit/larabuilder:'role'to the$fillablearray.$castsproperty with'role' => RoleEnum::classmapping.RoleEnumat the top ofUser.phpviause App\Enums\User\RoleEnum;.Expected outcome
What is the expected result?
role(values: 'admin', 'user') on theuserstable withoutrole_idor any dependency on therolestable.RoleEnumenum file atapp/Enums/User/RoleEnum.phpused consistently across generated backend code.ClerkUserRepositorythat assigns userrolesusing the enum value.A
User.phpmodel automatically updated to:role.RoleEnum.RoleEnumproperly.add_default_user.phpmigration that uses theroleenum field instead ofrole_id.Verification scenarios
How can this be tested?
roleenum column with correct values and norole_id.RoleEnumfile exists and follows naming/location conventions.ClerkUserRepository::fromTokenmethod assigns the role viaenumvalue correctly and creates or finds the user byclerk_id.User.phpcontains'role'in$fillable, has the proper$castsentry, and imports the enum.roleshandled via the enum field.Resources
Materials (Screenshots, Figma Links, References)
https://github.com/RonasIT/larabuilder