<?php
namespace App\Http\Livewire\Components;
use Lunar\Facades\DB;
use Lunar\Models\Discount;
use Lunar\Hub\Http\Livewire\Components\Discounts\Types\AbstractDiscountType;
class CustomDiscountComponent extends AbstractDiscountType
{
/**
* The instance of the discount.
*
* @var Discount
*/
public Discount $discount;
/**
* {@ineheritDoc}.
*/
public function rules()
{
return [
'discount.data' => 'array',
];
}
/**
* {@inheritDoc}
*/
public function mount()
{
parent::mount();
}
public function getValidationMessages()
{
return [];
}
/**
* Handle when the discount data is updated.
*
* @return void
*/
public function updatedDiscountData()
{
$this->emitUp('discountData.updated', $this->discount->data);
}
/**
* Save the product discount.
*
* @return void
*/
public function save($discountId)
{
$this->discount = Discount::find($discountId);
DB::transaction(function () {
// ...
});
}
/**
* Render the livewire component.
*
* @return \Illuminate\View\View
*/
public function render()
{
return view('my-custom-discount-ui')
->layout('adminhub::layouts.base');
}
}