52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Data;
|
|
|
|
use Livewire\Wireable;
|
|
use Spatie\LaravelData\Concerns\WireableData;
|
|
use Spatie\LaravelData\Data;
|
|
|
|
class CategoryData extends Data implements Wireable
|
|
{
|
|
use WireableData;
|
|
|
|
public function __construct(
|
|
public ?int $id,
|
|
public string $name,
|
|
public string $description,
|
|
public string $slug,
|
|
public string $color,
|
|
) {
|
|
}
|
|
|
|
public static function blank(): self
|
|
{
|
|
return CategoryData::from([
|
|
'name' => '',
|
|
'description' => '',
|
|
'slug' => '',
|
|
'color' => '',
|
|
]);
|
|
}
|
|
|
|
public static function rules(): array
|
|
{
|
|
return [
|
|
'name' => ['required', 'string', 'max:128', 'unique:categories,name'],
|
|
'description' => ['required', 'string', 'max:255'],
|
|
'slug' => ['required', 'string', 'max:32'],
|
|
'color' => ['required', 'string', 'max:32'],
|
|
];
|
|
}
|
|
|
|
public static function messages(): array
|
|
{
|
|
return [
|
|
'name.required' => __('The name field is required.'),
|
|
'name.unique' => __('The name has already been taken.'),
|
|
'description.required' => __('The description field is required.'),
|
|
'slug.required' => __('The slug field is required.'),
|
|
'color.required' => __('The color field is required.'),
|
|
];
|
|
}
|
|
}
|