活动专区
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\SystemTool\Http\Requests;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Validation\Rules\Exists;
|
||||
use Modules\Common\Http\Requests\BaseFormRequest;
|
||||
use Modules\SystemTool\Models\SysCategoryModel;
|
||||
use Modules\SystemTool\Models\SysFileModel;
|
||||
|
||||
class SysActivityFormRequest extends BaseFormRequest
|
||||
{
|
||||
protected $stopOnFirstFailure = true;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string|max:100',
|
||||
'image_id' => ['required', 'integer', new Exists(SysFileModel::class, 'id')],
|
||||
'link_type' => 'nullable|integer|in:0,1',
|
||||
'link' => [
|
||||
'nullable',
|
||||
'string',
|
||||
'max:500',
|
||||
Rule::requiredIf(fn () => $this->input('link_type', 0) == 0),
|
||||
],
|
||||
'category_id' => [
|
||||
'nullable',
|
||||
'integer',
|
||||
Rule::requiredIf(fn () => $this->input('link_type', 0) == 1),
|
||||
new Exists(SysCategoryModel::class, 'id'),
|
||||
],
|
||||
'description' => 'nullable|string|max:5000',
|
||||
'status' => 'nullable|integer|in:0,1',
|
||||
'sort' => 'nullable|integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'title.required' => '活动标题是必填的',
|
||||
'title.max' => '活动标题不能超过 :max 个字符',
|
||||
'image_id.required' => '活动图片是必填的',
|
||||
'link_type.in' => '跳转类型只能是 0(链接)或 1(分类)',
|
||||
'link.required' => '链接模式下跳转链接是必填的',
|
||||
'link.max' => '跳转链接不能超过 :max 个字符',
|
||||
'category_id.required' => '分类模式下请选择分类',
|
||||
'description.max' => '活动描述不能超过 :max 个字符',
|
||||
'status.in' => '状态值只能是 0(启用)或 1(禁用)',
|
||||
'sort.integer' => '排序必须是整数',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user