mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
56 lines
1.3 KiB
PHP
56 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Rewards\Standards\Validators;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractValidation;
|
|
use App\Classes\Modules\Rewards\DataTransferObjects\RewardObject;
|
|
use App\Models\Reward;
|
|
|
|
class RewardValidation extends AbstractValidation
|
|
{
|
|
/**
|
|
* @param RewardObject $object
|
|
* @return array
|
|
*/
|
|
protected function data($object): array {
|
|
|
|
$data = [
|
|
'name'=> $object->getName(),
|
|
'description' => $object->getDescription(),
|
|
];
|
|
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @param null|string $type
|
|
* @return array
|
|
*/
|
|
protected function rules(): array {
|
|
return [
|
|
'name' => [
|
|
'required',
|
|
function ($attribute, $value, $fail) {
|
|
// Check if reward name already exists in the database
|
|
$existingMilestone = Reward::where('name', $value)->first();
|
|
if ($existingMilestone) {
|
|
$fail("The {$attribute} reward name already exists in the database.");
|
|
}
|
|
},
|
|
],
|
|
'description' => [
|
|
'required',
|
|
]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function messages(): array {
|
|
return [];
|
|
}
|
|
|
|
}
|