<?php

namespace App\Http\Requests\Admin\Master;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CategoryRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('categories.create')
            || $this->user()->can('categories.update');
    }

    public function rules(): array
    {
        $category = $this->route('category');

        return [
            'name' => ['required', 'string', 'max:50', Rule::unique('categories', 'name')->ignore($category)],
        ];
    }

    public function attributes(): array
    {
        return [
            'name' => 'nama',
        ];
    }
}
