每当我更新提交模型上的参数时,我都试图将设计者用户名从我的代理模型(current_agent.id)传递到我的嵌套AgentActivity模型中。我将如何实现这一目标?
当前,我在“提交”控制器上的代码(不会引发错误,但是什么也没做):
$validation = Validator::make($request->all(), [
'profile_photo'=> 'required|image|mimies:jpeg,png,jpg,gif|max:2048'
]);
if ($validation->passes()) {
//$image = $request->file('profile_photo');
$new_name = time().'.'.$request->image->getClientOriginalExtension();
$request->image->move(public_path("photo"),$new_name);
return response()->json([
'message' => 'Image uploaded successfully'
]);
} else {
return response()->json([
'message' => $validation->errors()->all(),
'profile_photo' => '',
'class_name' => 'danger'
]);
}
答案 0 :(得分:1)
是的,您只是分配agent_id,但不保存它。应该是:
@submission.agent_activities.first.update(agent_id: current_agent.id)
此行应在if @submission.update(submission_params)
之后