Unable to fetch value of filter on table and update widget

// SupplierTransactionWidget.php
protected $listeners = ['updateSupplierTransactionWidget' => '$refresh'];

protected function getViewData(): array
{
$supplierId = request()->has('tableFilters')
? request('tableFilters')['supplier_id']['value'] : null;
if ($supplierId) {
// The problem is that we are not able to read value from query string on when filter is changed
// dd('here');
$payable = Supplier::find($supplierId)->remainingPayable();
} else {
$bill = SupplierHistory::where('type', 'bill')->sum('amount');
$cheque = SupplierHistory::where('type', 'cheque')->sum('amount');
$payable = round($bill - $cheque, 2);
}
return ['payable' => formatMoney($payable)];
}

// ManagerSupplierHistories.php
public function updated($name)
{
if (Str::of($name)->contains(['tableFilters'])) {
$this->emit('updateSupplierTransactionWidget');
}
}
// SupplierTransactionWidget.php
protected $listeners = ['updateSupplierTransactionWidget' => '$refresh'];

protected function getViewData(): array
{
$supplierId = request()->has('tableFilters')
? request('tableFilters')['supplier_id']['value'] : null;
if ($supplierId) {
// The problem is that we are not able to read value from query string on when filter is changed
// dd('here');
$payable = Supplier::find($supplierId)->remainingPayable();
} else {
$bill = SupplierHistory::where('type', 'bill')->sum('amount');
$cheque = SupplierHistory::where('type', 'cheque')->sum('amount');
$payable = round($bill - $cheque, 2);
}
return ['payable' => formatMoney($payable)];
}

// ManagerSupplierHistories.php
public function updated($name)
{
if (Str::of($name)->contains(['tableFilters'])) {
$this->emit('updateSupplierTransactionWidget');
}
}
Solution:
Livewire
Events | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Jump to solution
6 Replies
Kiran Timsina
Kiran TimsinaOP17mo ago
Anyone?
Solution
LeandroFerreira
LeandroFerreira17mo ago
Livewire
Events | Livewire
A full-stack framework for Laravel that takes the pain out of building dynamic UIs.
Kiran Timsina
Kiran TimsinaOP17mo ago
Thank you! Got it to work. Cheers. And thanks for the blog too! You're awesome!
pechtelt
pechtelt16mo ago
@thekiranspage how did you get this to work?
pechtelt
pechtelt16mo ago
Thanks mate!
Want results from more Discord servers?
Add your server