resetValidation(); $this->resetErrorBag(); $this->method = $method; $this->modalTitle = $modalTitle; $this->form->tier_id = $tier_id; $this->rewards = TierReward::where('tier_id', $tier_id) ->get() ->map(fn (TierReward $reward) => [ 'hash' => $reward->hash, 'tier_id' => $reward->tier_id, 'name' => $reward->name, 'value' => currency($reward->value, 'Rp'), ]) ->toArray(); if ($id) { $this->form->setRewards(TierReward::byHashOrFail($id)); } } public function create() { $this->canOrAbort('create tier reward'); $this->form->store(); $this->dispatch('data:tiersUpdated')->to(Tier::class); $this->toast('Hadiah berhasil ditambahkan.'); Flux::modal('reward-form-modal')->close(); } public function update() { $this->canOrAbort('update tier reward'); $this->form->update(); $this->toast('Hadiah berhasil diperbarui.'); Flux::modal('reward-form-modal')->close(); } public function delete(TierReward $reward) { $reward->delete(); $this->toast('Hadiah berhasil dihapus.'); $this->dispatch('data:tiersUpdated')->to(Tier::class); Flux::modal('delete')->close(); $this->rewards = array_values(array_filter($this->rewards, fn ($item) => $item['hash'] !== $reward->hash)); } public function render() { return view('livewire.studio.loyalty.tier.reward', [ 'pageTitle' => 'Hadiah', ]); } }