最近发表的话题
最近发表的评论
  • 「分享」自己写的标记单条消息为已读 at 1天前

    @hustnzj
    加了个判断,不然未读数为0的话会报sql错误。

    file

    app\Http\Controllers\Api\NotificationsController.php

        public function readSingle(DatabaseNotification $notification)
        {
            if (!$notification->read_at) {
                $this->user()->decrement('notification_count');
                $notification->markAsRead();
            }
            return $this->response->noContent();
        }
  • 路由写成 user/notifications/read 是不是更贴切 at 1天前

    @liyu001989
    谢谢啦!突然理解了。
    刚再翻了下资料 理解 RESTful 架构
    user/read/notifications 是把用户读取通知这个服务看作一种一种资源,
    如果写成 user/notifications/read 就变成对用户通知这个资源进行读的操作,URI 中包含了 read 这个动作,是不符合 RESTful HTTP API 的设计理念的, 所以老师的这种写法才是正确的。

  • Laravel Conf China 2019 之 安正超 at 4天前

    :+1:帅

  • 使用了 liyu/dingo-serializer-switch 中间件 为什么分类列表返回的数据还有 data 包裹 at 5天前

    @liyu001989 明白了 谢谢啦

  • 手机号注册以后就不能再发送验证码了 at 3周前

    @liyu001989 明白了,谢谢啦。

  • 手机号注册以后就不能再发送验证码了 at 3周前

    更改如下:

    在用户注册接口传递 phone 参数

    app\Http\Requests\Api\UserRequest.php 中增加验证

        ...
        public function rules()
        {
            return [
                'name' => 'required|between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name',
                'password' => 'required|string|min:6',
                'verification_key' => 'required|string',
                'verification_code' => 'required|string',
                'phone' => [
                    'required',
                    'regex:/^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\d{8}$/',
                    'unique:users'
                ]
            ];
        }
        ...

    app\Http\Controllers\Api\UsersController.php 验证 phone 与发送验证码接口提交的 phone 是否一致

           ...
            if (!hash_equals($verifyData['code'], $request->verification_code) or $verifyData['phone'] != $request->phone) {
                // 返回401
                return $this->response->errorUnauthorized('验证码错误');
            }
           ...
  • 解决 Windows 系统使用 Homestead 运行 Laravel 本地项目响应缓慢问题 at 1个月前

    重启出现如下问题

    $ vagrant.exe provision && vagrant.exe reload
    There are errors in the configuration of this machine. Please fix
    the following errors and try again:
    
    shell provisioner:
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh
    * `path` for shell provisioner does not exist on the host system: C:/Users/wanger/Homestead/scripts/serve-nfs.sh