94 lines
4.9 KiB
PHP
94 lines
4.9 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace plugin\article\app\validate;
|
||
|
|
|
||
|
|
use core\base\BaseValidate;
|
||
|
|
use Illuminate\Validation\Rule;
|
||
|
|
use plugin\article\app\model\Content;
|
||
|
|
|
||
|
|
class ContentValidate extends BaseValidate
|
||
|
|
{
|
||
|
|
public function rules(): array
|
||
|
|
{
|
||
|
|
$id = request()->route?->param('id');
|
||
|
|
|
||
|
|
return [
|
||
|
|
'title' => ['required', 'max:200', Rule::unique(Content::class, 'title')->ignore($id, 'id')],
|
||
|
|
'content_type' => ['nullable', 'max:50'],
|
||
|
|
'slug' => ['nullable', 'max:200', Rule::unique(Content::class, 'slug')->ignore($id, 'id')],
|
||
|
|
'category_id' => ['required', 'integer'],
|
||
|
|
'channel' => ['nullable', 'max:100'],
|
||
|
|
'visibility' => ['nullable', 'integer', 'in:1,2,3'],
|
||
|
|
'author' => ['nullable', 'max:100'],
|
||
|
|
'source' => ['nullable', 'max:100'],
|
||
|
|
'cover' => ['nullable', 'max:255'],
|
||
|
|
'seo_keywords' => ['nullable', 'max:255'],
|
||
|
|
'seo_title' => ['nullable', 'max:200'],
|
||
|
|
'seo_description' => ['nullable', 'max:500'],
|
||
|
|
'summary' => ['nullable', 'max:500'],
|
||
|
|
'content' => ['nullable'],
|
||
|
|
'status' => ['nullable', 'integer', 'in:0,1,2'],
|
||
|
|
'is_top' => ['nullable', 'integer', 'in:0,1'],
|
||
|
|
'is_recommend' => ['nullable', 'integer', 'in:0,1'],
|
||
|
|
'allow_comment' => ['nullable', 'integer', 'in:0,1'],
|
||
|
|
'sort' => ['nullable', 'integer', 'min:0'],
|
||
|
|
'view_count' => ['nullable', 'integer', 'min:0'],
|
||
|
|
'like_count' => ['nullable', 'integer', 'min:0'],
|
||
|
|
'comment_count' => ['nullable', 'integer', 'min:0'],
|
||
|
|
'favorite_count' => ['nullable', 'integer', 'min:0'],
|
||
|
|
'published_at' => ['nullable', 'integer'],
|
||
|
|
'offline_at' => ['nullable', 'integer'],
|
||
|
|
'tag_ids' => ['nullable', 'array'],
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
protected array $message = [
|
||
|
|
'title.required' => '文章标题不能为空',
|
||
|
|
'title.max' => '文章标题不能超过200个字符',
|
||
|
|
'title.unique' => '文章标题已存在',
|
||
|
|
'content_type.max' => '内容类型不能超过50个字符',
|
||
|
|
'slug.max' => '文章标识不能超过200个字符',
|
||
|
|
'slug.unique' => '文章标识已存在',
|
||
|
|
'category_id.required' => '请选择内容分类',
|
||
|
|
'category_id.integer' => '内容分类格式不正确',
|
||
|
|
'channel.max' => '所属频道不能超过100个字符',
|
||
|
|
'visibility.integer' => '可见范围格式不正确',
|
||
|
|
'visibility.in' => '可见范围值不正确',
|
||
|
|
'author.max' => '作者不能超过100个字符',
|
||
|
|
'source.max' => '内容来源不能超过100个字符',
|
||
|
|
'cover.max' => '封面地址不能超过255个字符',
|
||
|
|
'seo_keywords.max' => 'SEO关键词不能超过255个字符',
|
||
|
|
'seo_title.max' => 'SEO标题不能超过200个字符',
|
||
|
|
'seo_description.max' => 'SEO描述不能超过500个字符',
|
||
|
|
'summary.max' => '摘要不能超过500个字符',
|
||
|
|
'status.integer' => '状态格式不正确',
|
||
|
|
'status.in' => '状态值不正确',
|
||
|
|
'is_top.integer' => '置顶状态格式不正确',
|
||
|
|
'is_top.in' => '置顶状态值不正确',
|
||
|
|
'is_recommend.integer' => '推荐状态格式不正确',
|
||
|
|
'is_recommend.in' => '推荐状态值不正确',
|
||
|
|
'allow_comment.integer' => '评论设置格式不正确',
|
||
|
|
'allow_comment.in' => '评论设置值不正确',
|
||
|
|
'sort.integer' => '排序必须为整数',
|
||
|
|
'sort.min' => '排序不能小于0',
|
||
|
|
'view_count.integer' => '浏览量必须为整数',
|
||
|
|
'view_count.min' => '浏览量不能小于0',
|
||
|
|
'like_count.integer' => '点赞量必须为整数',
|
||
|
|
'like_count.min' => '点赞量不能小于0',
|
||
|
|
'comment_count.integer' => '评论量必须为整数',
|
||
|
|
'comment_count.min' => '评论量不能小于0',
|
||
|
|
'favorite_count.integer' => '收藏量必须为整数',
|
||
|
|
'favorite_count.min' => '收藏量不能小于0',
|
||
|
|
'published_at.integer' => '发布时间格式不正确',
|
||
|
|
'offline_at.integer' => '下线时间格式不正确',
|
||
|
|
'tag_ids.array' => '标签数据格式不正确',
|
||
|
|
];
|
||
|
|
|
||
|
|
protected array $scene = [
|
||
|
|
'store' => ['title', 'content_type', 'slug', 'category_id', 'channel', 'visibility', 'author', 'source', 'cover', 'seo_keywords', 'seo_title', 'seo_description', 'summary', 'content', 'status', 'is_top', 'is_recommend', 'allow_comment', 'sort', 'view_count', 'like_count', 'comment_count', 'favorite_count', 'published_at', 'offline_at', 'tag_ids'],
|
||
|
|
'update' => ['title', 'content_type', 'slug', 'category_id', 'channel', 'visibility', 'author', 'source', 'cover', 'seo_keywords', 'seo_title', 'seo_description', 'summary', 'content', 'status', 'is_top', 'is_recommend', 'allow_comment', 'sort', 'view_count', 'like_count', 'comment_count', 'favorite_count', 'published_at', 'offline_at', 'tag_ids'],
|
||
|
|
];
|
||
|
|
}
|