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



我有一个表单,其中包含带有数组的输入名称,例如:

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 不起作用

你可以试试这个,我想这会起作用

$reuest->user_profile->出生日期 = 碳::p arse(内爆("-", [$request->user_profile['birth_day'], $request->user_profile['birth_month'],$request->user_profile['birth_year']](((->格式('Y-m-d'(;

最新更新