contact_report可以包含许多contact_report_actions。我的表可能看起来像这样
Project
id | data |
----------------------
1 | something |
----------------------
document
id | data | project_id
---------------------------------
1 | something | 1
---------------------------------
document_actions
action | deliveryDate | documentID
--------------------------------------------
Walk dog | 01/01/2016 | 1
--------------------------------------------
Wash clothes | 08/02/2016 | 1
--------------------------------------------
Party | 09/02/2016 | 1
--------------------------------------------
我在更新contact_report_actions表时遇到了一些问题。目前我正在尝试这样的事情:
public function update(Project $project)
{
$project->contactReportDoc->discussionPoints = Input::get('discussionPoints');
$actions = Input::get('actionInput');
foreach($actions as $action => $input) {
$contactReportActionsDoc = ContactReportActionsDoc::firstOrNew(['action' => $input["action"]]);
$contactReportActionsDoc->action = $input["action"];
$contactReportActionsDoc->responsibility = $input["responsibility"];
$contactReportActionsDoc->save();
}
$project->contactReportDoc->update();
$projectId = $project->id;
$contactReportDoc = ContactReportDoc::where('projectId', '=', $projectId)->first();
return Redirect::route('projects.contactReportDoc.edit', compact('project', 'contactReportDoc'));
}
$actions
是用户的输入。我要做的是查看操作是否已存在,如果已存在,请更新它。否则我需要为新操作创建一个新行。我似乎无法将它传递给actions数组并调用此更新,因为它抱怨函数更新不存在。如何更新contact_report_actions
表中的行?
由于