12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Http\Requests\API\User;
- use App\Http\Requests\RuleHelper;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Hash;
- class UpdateRequest extends FormRequest
- {
- use RuleHelper;
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
- */
- public function rules(): array
- {
- return [
- 'name' => 'required|max:100',
- 'email' => 'required|email',//为了编辑时没改邮箱的情况不用required|email|unique:users
- 'password' =>'nullable|min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{6,}$/', // 编辑时可为空,包含大小写字母和数字,At least 6 digits, including upper and lower case letters and numbers
- 'auth_password' => [
- 'required',
- function ($attribute, $value, $fail) {
- if (!Hash::check($value, Auth::user()->password)) {
- $fail("Wrong security authentication password!");
- }
- }
- ],
- 'phone'=>'nullable|regex:/^\d{8,11}$/',
- 'gender'=>'nullable|in:1,0',
- 'address'=>'nullable|max:255',
- 'company_id'=>'exists:company,id',
- 'department_id'=>'nullable|exists:department,id',
- 'role_id'=>'required|exists:roles,id',
- ];
- }
- }
|