<?php
/**
 * ${CARET}
 * @file:CpRequest.php
 * @Created by gnitif
 * @Date: 2023/3/22
 * @Time: 17:06
 */


namespace Modules\System\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Modules\System\Models\NoticeTypes;


class NoticeTypeRequest extends  FormRequest
{

    /**
     * rules
     *
     * @return array
     */
    public function rules(): array
    {
        return [
                'name' => [
                'required',
                function ($attribute, $value, $fail) {
                    $has = NoticeTypes::where('is_deleted', 0)->where('name', $value)->value('id');
                    if (!empty($has)) {
                        $fail("分类已存在！");
                    }
                }
            ]
        ];
    }
    /**
     * messages
     *
     * @return string[]
     */
    public function messages(): array
    {
        return [
            'name.required' => '分类名称必须填写',
        ];
    }
}
