【发布时间】:2023-03-19 13:50:01
【问题描述】:
我正在使用 Laravel 8 构建一个项目并安装了https://github.com/rebing/graphql-laravel,以便在我的项目中使用 GraphQL。我有一个名为“UpdateUserMutation”的突变,它从突变扩展而来,它有一个 args 函数来检索用户发送的数据。基本上是这样的;
public function args(): array
{
return [
'id' => [
'name' => 'id',
'type' => Type::nonNull(Type::int()),
'rules' => [
'required',
'numeric',
'exists:users'
]
],
'name' => [
'name' => 'name',
'type' => Type::string(),
'rules' => [
'string',
'min:3',
'max:191'
]
],
'email' => [
'name' => 'email',
'type' => Type::string(),
'rules' => [
'string',
'min:3',
'max:191',
'email:rfc,dns',
'unique:users,email,' . 'id'
]
],
'department_id' => [
'name' => 'department_id',
'type' => Type::int(),
'rules' => [
'numeric',
'exists:departments,id'
]
]
];
}
```
I define Laravel validation rules inside of each element. I need to define the 'unique' rule for the email field but of course, I need to exclude that user's email address if the user doesn't change his/her email address. So, I need to access the id element which is inside args function. How can I do that?
【问题讨论】: