【发布时间】:2019-06-06 17:11:47
【问题描述】:
我有一个表单,其中包含带有数组的输入名称,示例:
user_profile[birth_day]
user_profile[birth_month]
user_profile[birth_year]
user_profile[birthdate]
现在我想将它们组合起来并创建一个新的请求属性。
我找到了解决方案,但我知道这是不好的做法:
$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]);
当我得到$request->user_profile['birthdate'] 时,它会返回正确的输入(如果已填写)。但是当我尝试修改$request->user_profile['birthdate'] 时它为空时:
$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');
我收到以下错误:
间接修改重载属性 Illuminate\Http\Request::$user_profile 无效
【问题讨论】:
标签: php laravel-5.8