doukang7858 2019-06-05 13:14 采纳率: 0%
浏览 99

修改request()数组返回错误间接修改重载属性

I have a form which includes input names with arrays, examples:

user_profile[birth_day]
user_profile[birth_month]
user_profile[birth_year]
user_profile[birthdate]

now i want to combine them and make a new request property.

i found a solution but i know it's bad practice:

$user_profile['birthdate'] = Carbon::parse(implode("-", [$request->user_profile['birth_day'], $request->user_profile['birth_month'], $request->user_profile['birth_year']]))->format('Y-m-d');
$request->request->add(['user_profile' => $user_profile+$request->user_profile]);

When i get $request->user_profile['birthdate'] it returns the correct input, if filled in. But when i try to modify $request->user_profile['birthdate'] when it is empty with:

$reuest->user_profile['birthdate'] = Carbon::parse(implode("-", [$request->user_profile['birth_day'], $request->user_profile['birth_month'], 
$request->user_profile['birth_year']]))->format('Y-m-d');

i get the following error:

Indirect modification of overloaded property Illuminate\Http\Request::$user_profile has no effect

  • 写回答

1条回答 默认 最新

  • dongqin1819 2019-06-06 09:11
    关注

    You can try this, I guess this will work

    $reuest->user_profile->birthdate = Carbon::parse(implode("-", [$request->user_profile['birth_day'], $request->user_profile['birth_month'], $request->user_profile['birth_year']]))->format('Y-m-d');

    评论

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题