Livewire Component Not Working

Hello, I add a livewire component consisting on a select of options. When the select changes, nothing happens (can't see a network request on devtools). This is the livewire component:
<?php

namespace App\Livewire;

use App\Models\Agency;
use Livewire\Component;

class SelectAgency extends Component
{
public $selectedOption;

public $options = [];

public function mount()
{
$this->selectedOption = session('agency.id');
$this->fetchOptions();
}

public function fetchOptions()
{
$this->options = Agency::where('status_id', 3)->pluck('name', 'id')->toArray();
}

public function updatedSelectedOption($value)
{
session(['agency.id' => $value]);
}

public function render()
{
return view('livewire.select-agency');
}
}
<?php

namespace App\Livewire;

use App\Models\Agency;
use Livewire\Component;

class SelectAgency extends Component
{
public $selectedOption;

public $options = [];

public function mount()
{
$this->selectedOption = session('agency.id');
$this->fetchOptions();
}

public function fetchOptions()
{
$this->options = Agency::where('status_id', 3)->pluck('name', 'id')->toArray();
}

public function updatedSelectedOption($value)
{
session(['agency.id' => $value]);
}

public function render()
{
return view('livewire.select-agency');
}
}
The component renders fine, but on change nothing happens.
3 Replies
AmauryCid
AmauryCid2mo ago
This is the blade code:
<div>
<div
class="fi-input-wrp flex rounded-lg shadow-sm ring-1 transition duration-75 bg-white dark:bg-white/5 [&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-2 ring-gray-950/10 dark:ring-white/20 [&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-primary-600 dark:[&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-primary-500 fi-fo-select">
<select wire:model="selectedOption"
class="fi-select-input block w-full border-none bg-transparent py-1.5 pe-8 text-base text-gray-950 transition duration-75 focus:ring-0 disabled:text-gray-500 disabled:[-webkit-text-fill-color:theme(colors.gray.500)] dark:text-white dark:disabled:text-gray-400 dark:disabled:[-webkit-text-fill-color:theme(colors.gray.400)] sm:text-sm sm:leading-6 [&amp;_optgroup]:bg-white [&amp;_optgroup]:dark:bg-gray-900 [&amp;_option]:bg-white [&amp;_option]:dark:bg-gray-900 ps-3">
<option value="">Select Agency...</option>
@foreach ($options as $value => $label)
<option value="{{ $value }}">{{ $label }}</option>
@endforeach
</select>
</div>
</div>
<div>
<div
class="fi-input-wrp flex rounded-lg shadow-sm ring-1 transition duration-75 bg-white dark:bg-white/5 [&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-2 ring-gray-950/10 dark:ring-white/20 [&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-primary-600 dark:[&amp;:not(:has(.fi-ac-action:focus))]:focus-within:ring-primary-500 fi-fo-select">
<select wire:model="selectedOption"
class="fi-select-input block w-full border-none bg-transparent py-1.5 pe-8 text-base text-gray-950 transition duration-75 focus:ring-0 disabled:text-gray-500 disabled:[-webkit-text-fill-color:theme(colors.gray.500)] dark:text-white dark:disabled:text-gray-400 dark:disabled:[-webkit-text-fill-color:theme(colors.gray.400)] sm:text-sm sm:leading-6 [&amp;_optgroup]:bg-white [&amp;_optgroup]:dark:bg-gray-900 [&amp;_option]:bg-white [&amp;_option]:dark:bg-gray-900 ps-3">
<option value="">Select Agency...</option>
@foreach ($options as $value => $label)
<option value="{{ $value }}">{{ $label }}</option>
@endforeach
</select>
</div>
</div>
And this is how I included:
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn (): string => Blade::render('@livewire(\'select-agency\')'),
);
FilamentView::registerRenderHook(
PanelsRenderHook::USER_MENU_BEFORE,
fn (): string => Blade::render('@livewire(\'select-agency\')'),
);
What I'm trying to do here is a global filter on the top navbar. I'm trying to achieve that after a selection, a session variable is setted and trigger a filament component refresh (resource, page). models already have a scope that checks this session variable to query the results.
LeandroFerreira
LeandroFerreira2mo ago
shouldn't you use wire:model.live ?
AmauryCid
AmauryCid2mo ago
That did it! Thank you Leandro! 🙂
Want results from more Discord servers?
Add your server
More Posts
Fileupload on registration page - 419 errorFor full context, we have a Filament app with 2 panels - Admin & Member. When a member registers, anCan't login into panel when user model use uuidHello i'm using uuid's on mi user model, I have configured all what is necessary to use it but I caAuthorize Imports: Apply different policy methods on create and updateI am using `authorize` method for Importer to show it only to the users that have `create` authorizaReplicate action: load form instead of saveI was searching for a way to add ***Clone*** table action, and came across ***Replicate*** action. TFilament Shield allows create/edit/delete despite role restrictions. Shouldn't have these permissionThe Filament plugin shield still allows users to create, edit, and delete even though I have not givCheck for user profile completeHi! My user model has some extra fields that I would like to be completed. My UserPanel is like this->RenderHook() problem in AdminPanelProvider.php | Class "Filament\View\PanelsRenderHook" not foundHello. I had this same configuration in my last application two months ago and had no problems. ForHas anyone implement QR Code Scanner in a field for filament?So a simple QR that will fill in a certain field on successful scanfileUpload download file directly to download folderPleas, probably i'm doing something wrong, i use file upload component with s3, everything works finForm in resource index pageI'm creating a resource to edit an invoice template, so I only need one data entry, and I don't want