所以,我有一个报告系统,它从我的表单收集日期到数据库。我只想更新,在新闻表中,列活动,输入隐藏名称 =“活动”,当我点击我的表单上的提交时,我不知道怎么做。我现在只是将输入保存在报告中,但我还想更新新闻中的活动列。路线Route::post('career_report', 'CareerSolutionController@careerReport');这是我的控制器public function careerReport(requ $request, $id) { $report = \App\Reports::create([ 'user_id' => $request['user_id'], 'username' => $request['username'], 'user_id_posted' => $request['user_id_posted'], 'username_posted' => $request['username_posted'], 'career_solution_id' =>$request['career_solution_id'], 'subject' =>$request['subject'], 'why_reporting' =>$request['why_reporting'], 'why_reporting_message' =>$request['why_reporting_message'], 'additional_message' =>$request['additional_message'], 'comment' =>$request['comment'], 'comment_user' =>$request['comment_user'], 'comment_id' =>$request['comment_id'], ]); $news = News::findOrfail($id); $news->active = $request['active']; $news->save(); if($news != ""){ flash('News has been updated successfully', 'success'); }else{ flash('News update fail', 'warning'); } if($report != ""){ flash('Career solution report submited', 'success'); }else{ flash('Career solution report', 'warning'); } return Redirect::back(); }现在,我需要在提交时将active输入保存type="hidden"在News表格、列active中。如何active仅在从报告提交时使用新输入更新列?
1 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
这里有几个选项:
如果您想从以下位置获取 $id:
public function careerReport(requ $request, $id)
您的路线应如下所示:
Route::post('career_report/{id}', 'CareerSolutionController@careerReport');
并将 id 添加到路由中:
<form role="form" action="/career_report/{{ $news->id }}" method="post" id="yourFormId">
或者您可以使用表单上的 ID,从函数中删除 $id
public function careerReport(requ $request)
并这样做:
$id = $request['career_solution_id']; // looks like this is the ID you ar looking for
$news = News::findOrfail($id);
$news->active = $request['active'];
$news->save();
- 1 回答
- 0 关注
- 125 浏览
添加回答
举报
0/150
提交
取消