<?php

namespace Modules\Mall\Rules;

use Illuminate\Contracts\Validation\Rule;
use Modules\Mall\Models\Region;

class DistrictRule implements Rule
{

    /**
     * Notes: 判断是否通过验证规则
     * @Author: <C.Jason>
     * @Date  : 2020/11/6 9:56 上午
     * @param  string  $attribute
     * @param  mixed   $value
     * @return bool
     */
    public function passes($attribute, $value): bool
    {
        $district = Region::find($value);
        if ($district->depth != 3) {
            return false;
        }

        return true;
    }

    /**
     * 获取校验错误信息
     * @return string
     */
    public function message(): string
    {
        return '区县信息选择有误';
    }

}
