dongzhuner6981 2018-06-29 21:38
浏览 15

在Laravel请求中保留新行

I'm using Laravel to pass a JSON And storing the request into a model The JSON that I'm passing is of the form

{
    "key": "GEnFcIB5UBScbwrM9OfBqYzY0/8=
",
} 

But when storing it to the DB, the key is stored as GEnFcIB5UBScbwrM9OfBqYzY0/8=

This is what I get when I dump the request

  Request {#42
      #json: ParameterBag {#24
        #parameters: array:1 [
          "key" => "GEnFcIB5UBScbwrM9OfBqYzY0/8="
          ]
      }

        ...

      #content: "{"key":"GEnFcIB5UBScbwrM9OfBqYzY0/8=
"}",

        ...

    }

As you can see the #content is showing the " ", but $request->key discards it and eventually is not saved in the DB

Any suggestions?

  • 写回答

1条回答 默认 最新

  • doudai8783 2018-06-29 21:59
    关注

    This might very well be due to trimming.

    https://laravel.com/docs/5.6/requests#input-trimming-and-normalization

    By default, Laravel includes the TrimStrings and ConvertEmptyStringsToNull middleware in your application's global middleware stack. These middleware are listed in the stack by the App\Http\Kernel class. These middleware will automatically trim all incoming string fields on the request, as well as convert any empty string fields to null. This allows you to not have to worry about these normalization concerns in your routes and controllers.

    If you would like to disable this behavior, you may remove the two middleware from your application's middleware stack by removing them from the $middleware property of your App\Http\Kernel class.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)