<?php
// +----------------------------------------------------------------------
// | onezan-admin 快速开发的管理平台
// +----------------------------------------------------------------------
// | 官方网址：https://www.onezan.cn
// +----------------------------------------------------------------------
// | onezan团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: 543885307@qq.com
// +----------------------------------------------------------------------
namespace Applications\sample\modules\article\validate\admin;
use think\Validate;
/**
 * Article Validator
 * @package Applications\sample\modules\article\validate\admin
 */
class ArticleValidator extends Validate
{
    protected $rule = [
        'id'          => 'integer|egt:1',
        'title'       => 'require|max:100',
        'category_id' => 'integer',
        'cover_image' => 'max:500',
        'content'     => 'max:65535',
        'audio_url'   => 'max:500',
        'source_url'  => 'max:500',
        'price'       => 'float|>=:0',
        'status'      => 'require|in:0,1',
    ];
    protected $message = [
        'title.require'  => '标题不能为空',
        'title.max'      => '标题不能超过100字',
        'content.max'    => '内容过长',
        'status.require' => '状态不能为空',
    ];
    protected $scene = [
        // create: required fields for new article
        'create' => ['title', 'category_id', 'cover_image', 'content', 'audio_url', 'source_url', 'price', 'status'],
        // update: only validate present fields
        'update' => ['title', 'category_id', 'cover_image', 'content', 'audio_url', 'source_url', 'price', 'status'],
        // save: backward compatible, unified create+update like all other modules
        'save'   => ['title', 'category_id', 'cover_image', 'content', 'audio_url', 'source_url', 'price', 'status'],
        // delete: only validate id
        'delete' => ['id'],
    ];
}
