Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marinarusalka's avatar

Adding optional fields to user registration

Hello.

I'm using Laravel 13.5.0 with Livewire starter kit. I've added four new fields to my users model in Laravel: "organization", which is required, "orcid" and "orgurl", which are optional, and "role", which is optional and also not entered by the user on the registration page but to be left as null until set separately by the website admin. I made "orcid", "orgurl" and "role" nullable in the database. I set "organization", "orgurl" and "orcid" as Fillable in User. php, and made the following code changes:

In register.blade.php:

<div class="flex items-center gap-4">
            <label for="organization" class="text-sm font-medium text-zinc-700">Organization*</label>
            <flux:input
                name="organization"
                type="text"
                required
                autocomplete="organization"
                :placeholder="__('organization')"
            />
 </div>
<div class="flex items-center gap-4">
            <label for="orgurl" class="text-sm font-medium text-zinc-700">Organization URL</label>
            <flux:input
                name="orgurl"
                type="text"
                nullable
                autocomplete="organization url"
                :placeholder="__('organization url')"
            />
 </div>

and

<div class="flex items-center gap-4">
            <label for="orcid" class="text-sm font-medium text-zinc-700">Orcid ID</label>
            <flux:input
                name="orcid"
                type="text"
                nullable
                autocomplete="orcid ID"
                :placeholder="__('orcid ID')"
            />
 </div>

In CreateNewUser.php, I added these lines to User::create

'orcid' => $input['orcid'],
 'organization' => $input['organization'],
'orgurl" => $input[''orgurl'],

In ProfileValidationRules, I added two new rules:

/** 
     * Validate required contact fields
    * @return array<int, ValidationRule|array<mixed>|string>
    */
    protected function contactReqRules(): array
    {
        return ['required', 'string', 'max:255'];
    }

    /** 
     * Validate optional contact fields
    * @return array<int, ValidationRule|array<mixed>|string>
    */
    protected function contactOptRules(): array
    {
        return ['nullable', 'string', 'max:255'];
    }

And added the following to profileRules:

'orcid' => $this->contactOptRules(),
 'organization' => $this->contactReqRules(),
 'orgurl' => $this->contactOptRules(),

If I then try to register a new user account, I don't get any errors, but the account doesn't get created either. The register page stays where it is, and nothing is saved to the database. I'm guessing that this is because I'm not doing any handling for the "role" field, but I'm not sure what I'm supposed to do for it. I'm new to Laravel and Livewire, so help, please?

1 like
4 replies
vincent15000's avatar

If you are new to Laravel, you should start following this series.

https://laracasts.com/series/laravel-from-scratch-2026

What do you mean when you say that **The register page stays where it is``` ? Do you mean that after submitting the form, you stay on the form ? If yes, that means that you have a validation rule that is not satisfied.

marinarusalka's avatar

Yes, after I click "Create account," I stay on the form. The focus changes back to the first input field ("Name"), but no error message appears.

Also, I did go through the Laravel Bootcamp seriesl, I'm not sure how similar it is to the one you linked.

1 like
vincent15000's avatar

In your code, I don't see anywhere some place with an error message.

<flux:input
    name="organization"
    type="text"
    nullable
    autocomplete="orcid ID"
    :placeholder="__('orcid ID')"
/>

You have to add the code to display the error it there is an error.

@error('organization')
    <span class="text-red-500">{{ $message }}</span>
@enderror
ghabriel25's avatar

Don't take your first step too high, if you're new to Laravel and Livewire I suggest learn from the basic. Here the videos that will help you understand how Laravel and Livewire works

I'd say, without understanding the basic you'll for sure having hard times debugging what wrong, why it doesn't work.

Some people choose to ask AI, sure it sometimes help you find the way to solve the problem but you're missing the important point where you are as developer should understand whats going on without relying AI to find the root cause.

1 like

Please or to participate in this conversation.