parfum/app/Livewire/Studio/Loyalty/Voucher/Create.php

56 lines
1.3 KiB
PHP

<?php
namespace App\Livewire\Studio\Loyalty\Voucher;
use App\Jobs\StorePushNotification;
use App\Livewire\Forms\Studio\Loyalty\VoucherForm;
use App\Models\Outlet;
use App\Models\PushNotification;
use App\Traits\WithAuthorization;
use App\Traits\WithOutletSelector;
use App\Traits\WithToast;
use App\Traits\WithUpdatedData;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Title('Tambah Voucher')]
class Create extends Component
{
use WithAuthorization, WithOutletSelector, WithToast, WithUpdatedData;
public VoucherForm $form;
public array $outlets;
public function mount()
{
$this->outlets = Outlet::pluck('name', 'id')->toArray();
}
public function save()
{
$this->canOrAbort('create voucher');
$this->form->store();
StorePushNotification::dispatch(
PushNotification::all(),
[
'title' => 'Voucher',
'body' => 'Ada voucher baru untuk kamu! Jangan sampai kelewatan, yuk cek sekarang dan nikmati penawarannya.',
],
);
$this->toast('Voucher berhasil ditambahkan.');
$this->redirectRoute('studio.loyalty.voucher.index');
}
public function render()
{
return view('livewire.studio.loyalty.voucher.form', [
'pageTitle' => 'Tambah Voucher',
]);
}
}