1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Http\Requests\API\User;
- use App\Http\Requests\RuleHelper;
- use App\Models\Company;
- use App\Models\Department;
- use App\Models\Role;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Validation\Rule;
- use Illuminate\Support\Facades\Hash;
- class BatchCreateRequest 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
- {
- // $departmentIds=[];
- // if(Auth::user()->super_admin){ //若是超级管理员可以查看所有部门,且添加
- // $departmentIds = Department::withoutGlobalScopes()->pluck('id')->toArray();
- //
- // }else{
- // $departmentIds = Department::pluck('id')->toArray();
- // }
- // $roleIds = Role::pluck('id')->toArray();
- //
- // $IdsAndDitto=$departmentIds;
- // $IdsAndDitto[] = 'ditto';
- //
- // $IdsAndDittoWithRole=$roleIds;
- // $IdsAndDittoWithRole[]='ditto';
- return [
- 'users.*.name' => 'required|max:100',
- 'users.*.email'=> 'required|email|unique:users',
- 'users.*.username'=>'required|max:30|unique:users',
- // '*.pwd_is_ditto'=>'required|in:1,0',取消密码同上
- 'users.*.password' => 'required|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
- 'users.*.gender'=>'nullable|in:1,0',
- 'users.*.company_id'=>'required|exists:company,id',
- 'users.*.department_id'=>'required|exists:department,id',
- 'users.*.role_id'=> 'required|exists:roles,id',
- 'auth_password' => [
- 'required',
- function ($attribute, $value, $fail) {
- if (!Hash::check($value, Auth::user()->password)) {
- $fail("Wrong security authentication password!");
- }
- }
- ],
- ];
- }
- }
|