无法更新 registration_id

使用Postman更新registration_id,提示:

{
    "message": "The given data was invalid.",
    "errors": {
        "name": [
            "用户名不能为空。"
        ],
        "email": [
            "邮箱 不能为空。"
        ]
    }
}

看了UserRequest.php文件,如果不提交nameemail在设定上确实会报错,为何课程截图用Postman可以成功修改registration_id

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
最佳答案

检查UserRequest.php的patch部分是否写对了:

.
.
.
case 'PATCH':
        $userId = auth('api')->id();

        return [
            'name' => 'between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,'.$userId,
            'email' => Rule::unique('users')->ignore($userId),
            'introduction' => 'max:80',
           'avatar_image_id' => Rule::exists('images', 'id')->where(function($query) use ($userId){
                $query->where('type', 'avatar')->where('user_id', $userId);
            })
        ];
        break;
.
.
.

nameemail都没有设required

5年前 评论
讨论数量: 4

检查UserRequest.php的patch部分是否写对了:

.
.
.
case 'PATCH':
        $userId = auth('api')->id();

        return [
            'name' => 'between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,'.$userId,
            'email' => Rule::unique('users')->ignore($userId),
            'introduction' => 'max:80',
           'avatar_image_id' => Rule::exists('images', 'id')->where(function($query) use ($userId){
                $query->where('type', 'avatar')->where('user_id', $userId);
            })
        ];
        break;
.
.
.

nameemail都没有设required

5年前 评论

@tsin larabbs的L03_6.x分支中,UserRequest.phpnameemail有设置了required

public function rules()
    {
        return [
            'name' => 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name,' . Auth::id(),
            'email' => 'required|email',
            'introduction' => 'max:80',
            'avatar' => 'mimes:jpeg,bmp,png,gif|dimensions:min_width=208,min_height=208',
        ];
    }
5年前 评论

@SeanSolomon 5.2. 编辑个人资料《L03 Laravel 教程 - 实战构架 API 服务器 ( Laravel 6.... 看这节,没有加required,加了required的参数没有传当然会返回相应的验证错误提示。

5年前 评论

@tsin 按这样修改可以。谢谢

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!