59 lines
1.1 KiB
PHP
59 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Forms;
|
|
|
|
use App\Models\Tier;
|
|
use Livewire\Form;
|
|
|
|
class TierForm extends Form
|
|
{
|
|
public ?Tier $tier = null;
|
|
|
|
public string $name = '';
|
|
|
|
public string $min_points = '';
|
|
|
|
public ?string $max_points = null;
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:50'],
|
|
'min_points' => ['required', 'numeric'],
|
|
'max_points' => ['nullable', 'numeric'],
|
|
];
|
|
}
|
|
|
|
public function validationAttributes(): array
|
|
{
|
|
return [
|
|
'name' => 'nama',
|
|
'min_points' => 'min. poin',
|
|
'max_points' => 'maks. poin',
|
|
];
|
|
}
|
|
|
|
public function setTier(Tier $tier)
|
|
{
|
|
$this->tier = $tier;
|
|
|
|
$this->name = $tier->name;
|
|
$this->min_points = $tier->min_points;
|
|
$this->max_points = $tier->max_points;
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$this->validate();
|
|
|
|
Tier::create($this->pull());
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
$this->validate();
|
|
|
|
$this->tier->update($this->pull());
|
|
}
|
|
}
|