\App\Http\Requests\Admin\ConcernsHasCommonRules

Request 公共字段规则 trait

职责:收敛全站 Request 的 status/sort/remark/name/code 规则与文案, 避免规则集群复制粘贴——一处改、处处改。

┌────────────────── 分区导航(按此顺序阅读)──────────────────┐ 分区 1 · 字段规则工厂 statusRule / sortRule / remarkRule / nameRule codeRule / uniqueRule 分区 2 · 通用文案 commonMessages └────────────────────────────────────────────────────────────┘

用法:use HasCommonRules 后,rules() 里 'status' => $this->statusRule(); 文案 array_merge($this->commonMessages('岗位'), [...实体特有...]); 同表唯一 'code' => $this->uniqueRule('td_sys_post', 'code', $id)

Summary

Methods
Properties
Constants
No public methods found
No public properties found
No constants found
statusRule()
sortRule()
remarkRule()
nameRule()
codeRule()
uniqueRule()
commonMessages()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

statusRule()

statusRule() : string

状态规则。

生成 Laravel 规则:nullable(可空)、integer(整数)、in:0,1(仅启用/停用两态)。

Returns

string —

sortRule()

sortRule() : string

排序号规则。

生成 Laravel 规则:nullable(可空)、integer(整数,用于升序排序)。

Returns

string —

remarkRule()

remarkRule() : string

备注规则。

生成 Laravel 规则:nullable(可空)、string(字符串)、max:255(最长 255 字符)。

Returns

string —

nameRule()

nameRule(int  $max = 64) : string

名称规则。

生成 Laravel 规则:nullable(可空)、string(字符串)、max(上限按实体可配,默认 64)。

Parameters

int $max

Returns

string —

codeRule()

codeRule(int  $max = 32) : string

编码规则。

生成 Laravel 规则:nullable(可空)、string、max(可配,默认 32)、 regex(字母开头 + 字母/数字/下划线,前后端同正则)。

Parameters

int $max

Returns

string —

uniqueRule()

uniqueRule(string  $table, string  $column, ?int  $ignoreId = null, ?callable  $where = null) : \Illuminate\Validation\Rules\Unique

同表同列唯一规则。

生成 Laravel 规则:Rule::unique(table, column) 的 unique 约束;ignore 忽略 自身 id(update 场景不与自己冲突);$where 用于 (type, code) 组合唯一等场景。

Parameters

string $table
string $column
?int $ignoreId
?callable $where

Returns

\Illuminate\Validation\Rules\Unique —

commonMessages()

commonMessages(string  $entity, int  $nameMax = 64) : array

通用字段中文文案。

实体名参数化(如「岗位」→「岗位编码不能超过 32 个字符」),返回字段规则 对应的 messages 数组,供各 Request 与实体特有文案合并。

Parameters

string $entity
int $nameMax

Returns

array —