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

jrdavidson's avatar

Dropdown Being Removed From DOM

I’m faced with a problem I can’t understand what’s happening. Currently when the role is changed and meets the correct criteria of the role then it shows the companies dropdown BUT it removes the dropdown of the roles.

<?php

namespace App\Http\Livewire;

use App\Models\Company;
use Livewire\Component;

class AddRoleForUser extends Component
{
    public $selectedRole;
    public $showCompaniesDropdown = false;

    public function updatedSelectedRole($role)
    {
        if (!is_null($role)) {
            $this->showCompaniesDropdown = in_array($role, ['admin', 'maintainer admin', 'user']);
        }
    }

    public function render()
    {
        return view('livewire.add-role-for-user', [
            'roles' => \Spatie\Permission\Models\Role::get()->pluck('name', 'name'),
            'companies' => Company::get()->pluck('name', 'id'),
        ]);
    }
}

<div>
    <div class="mb-8">
        <x-label
            class="text-gray-500"
            for="role"
            value="Role"
        />
        <x-select
            wire:model="selectedRole"
            id="role"
            name="role"
            class="block w-full mt-1"
            :options="$roles"
        />
    </div>
    @if ($showCompaniesDropdown)
        <div class="mb-8">
            <x-label
                class="text-gray-500"
                for="company"
                value="Company"
            />
            <x-select
                id="role"
                name="company"
                class="block w-full mt-1"
                :options="$companies"
            />
        </div>
    @endif
</div>

0 likes
0 replies

Please or to participate in this conversation.