Brammah's avatar

Dynamic Dependent Dropdown: Livewire

Hi Laracasts Community, I need some help. I have never used dependent dropdowns but I am open to learning. I have a form with different departments that are selected by a normal select input. When I select let's say, the accounts department on the select, another input (multi-select to be precise) should appear and list all members who belong to that department so that I may share with them information (e.g. a message to their phones) Kindly help.

0 likes
11 replies
Brammah's avatar

@Sinnbeck Yes, now what happens in the case where the first select input has to get different system users i.e. Accountants, Officials, Janitors, and Marketers, how do I load that, then use the tips you suggested?

Snapey's avatar

@Brammah in the render method, if the first dropdown is selected, query the database according to what was chosen

not more complicated than that really. If you need help show some code

Brammah's avatar

@Sinnbeck Oooh yes, they are, hehe, see my life? :D :D let me test and if I get any issues, I will get back to you. Thank you.

Brammah's avatar

Hi @sinnbeck and @snapey, I need your help, below is my Livewire Component.

	<?php

namespace App\Http\Livewire;

use Livewire\Component;
use App\Models\Accountant;
use App\Models\Janitor;
use App\Models\Marketer;

class Officials extends Component
{
    public $title;
    public $message;

    public $accountants;
    public $marketers;
    public $janitors;

    public function render()
    {
        $accountants= Accountant::all();
        $janitors= Janitor::all();
        $marketers= Marketer::all();

        return view('livewire.officials', compact('accountants', 'janitors', 'marketers'));
    }
}

Brammah's avatar

This is my blade:

        <div class="form-group col-md-6">
            <label for="recipient" class="text-dark d-block">Recipients: </label>
            <select class="form-control @error('recipient') is-invalid @enderror">
                    <option value="" selected>Select Recipient</option>
                    <option value="accountants">Accountants</option>
                    <option value="janitors">Janitors</option>
					<option value="marketers">Marketers</option>
            </select>
	    </div>
Brammah's avatar

The help I need is this; when I click on the blade where the value is, let's say, accountant, I want an input field to appear and it has the names of the accountants so that I can select either a few or all, to send them the message.

Snapey's avatar

@Brammah so i guess I need to improve the clarity of my tutorial as you have not implemented any of the ideas from it?

Brammah's avatar

@Snapey hehe, to be honest, I am new to Livewire and I am learning "on the fly". Apologies if it seems as though I went against your suggestion. :)

Please or to participate in this conversation.