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

marinarusalka's avatar

marinarusalka wrote a reply+100 XP

1d ago

Adding optional fields to user registration

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.

marinarusalka's avatar

marinarusalka started a new conversation+100 XP

1d ago

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?