1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?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 AdminUpdateRequest 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' => 'max:100',
- 'email'=> 'email|unique:users',
- 'username'=>'max:30|unique:users',
- 'password' => 'min:6|regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{6,}$/', // 至少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',
- 'gender'=>'in:1,0',
- 'address'=>'max:255',
- 'company_id'=>'exists:company,id',
- 'department_id'=>'exists:department,id',
- 'role_id'=>'exists:roles,id',
- ];
- }
- }
|