| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | <?phpnamespace App\Http\Requests\System;use App\Http\Models\Role;use App\Http\Requests\Request;use Illuminate\Validation\Rule;use Illuminate\Database\Query\Builder;class UpdateUserRequest extends Request{    /**     * Determine if the user is authorized to make this request.     *     * @return bool     */    public function authorize()    {        return true;    }    /**     * Get the validation rules that apply to the request.     *     * @return array     */    public function rules()    {        $addition = [];//        if ($this->input('role_id') == Role::TYPE_CUSTOMER) {        $addition['site_ids'] = 'nullable|array';//        }        return [                'nickname' => 'required',                'username' => [                    'required',                    'min:3',                    'max:15',                    Rule::unique('users')->where(function (Builder $query) {                        return $query->where('deleted_at', null);                    })->ignore($this->route('id'))                ],                'password' => 'nullable|min:5|max:15',                'phone' => [                    'nullable',                    Rule::unique('users')->where(function (Builder $query) {                        return $query->where('deleted_at', null);                    })->ignore($this->route('id'))                ],                'entry_time' => 'nullable',                'telephone' => 'nullable',                'email' => 'nullable',                'qq' => 'nullable',                'role_id' => 'required|numeric',                'status' => 'boolean',            ] + $addition;    }    public function attributes()    {        return [            'nickname' => '昵称',            'username' => '用户名',            'phone' => '手机号',            'password' => '密码',            'email' => '邮箱',            'qq' => 'qq号',            'role_id' => '角色',            'status' => '状态',            'sort' => '排序',            'site_id' => '站点',            'telephone' => '座机',        ];    }}
 |