Hi.
I’m trying to update a variable when i save a form. There is the main component and 2 other components inside that.
The main component is mainly responsible for the main view and showing some variables i.e. a customers credit_balance.
There is a form that updates in a scanning component which fires an event “$this->emitUp()” to the main component and from there i want it to update the customers credit balance.
When the event gets emitted, nothing happens!!! Ive tried emitUp(), emit(), EmitTo() and all do nothing.
When i look in the Inspector i can see the event there::
emits: [{event: "getCreditBalance", params: [], ancestorsOnly: true}]
0: {event: "getCreditBalance", params: [], ancestorsOnly: true}
But it never updates the customers balance on the screen.
What I have currently ::
// Main component
public $user;
public $credit_balance;
protected $listeners = ['getCreditBalance'];
public function getCreditBalance()
{
$this->user = User::where('id', $this->user->id)->firstOrFail();
$this->credit_balance = $this->user->creditBalance->current;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\\Illuminate\Http\Response
*/
public function getCreditBalance()
{
$this->user = User::where('id', $this->user->id)->firstOrFail();
$this->credit_balance = $this->user->creditBalance->current;
}
// Form component
public function dispatchScans()
{
$this->validate();
$this->emitUp('getCreditBalance');
$this->dispatchBrowserEvent('alert', __('alerts.scans_charged', ['number' => $this->total_scans]));
$this->reset_form();
}
Any help would be grateful.
Many thanks