每當我嘗試將某些內容更新到我的數據中時,我總是收到此錯誤。它最後一次沒有發生很多事情,但在放入新的更新函數後,錯誤不斷出現,出於某種原因,它指向我已經輸入的新函數,即使我正在更新舊函數。不斷收到錯誤:implode():更新數據時傳遞的參數無效
控制器:
//update for user
public function edit($id){
$object = user::find($id);
return view('edit', compact('object'));
}
public function update(Request $request, $id){
$object = user::find($id);
$object->Name = $request->input('Name');
$object->update();
return redirect('/home');
}
//update for Schools table
public function edit1($id){
$object2 = school::find($id);
return view('edit1', compact('object2'));
}
public function update1(Request $request, $id){
$object2 = school::find($id);
$test = array();
$test['School'] = implode(' , ', $request->School);
$test['SDate'] = implode(' , ', $request->SDate);
$test['EDate'] = implode(' , ', $request->EDate);
$object2->update($test);
return redirect('/home');
}
//error start here after putting this whole thing in. (I tried putting it into another separate controller but the error still continues)
public function edit2($id){
$object3 = hobby::find($id);
return view('edit2', compact('object3'));
}
public function update2(Request $request, $id){
$object3 = hobby::find($id);
$test2 = array();
$test2['computer_game'] = implode(' , ', $request->computer_game);
$test2['reading_book'] = implode(' , ', $request->reading_book);
$object3->update($test2);
return redirect('/home');
}
錯誤是突出這個部分,即使當我嘗試更新的用戶或學校數據
$test2['computer_game'] = implode(' , ', $request->computer_game);
它說
:implode(): Invalid arguments passed
我沒有問題更新愛好數據,但它的錯誤一直指向愛好implode部分。
是否有可能我只能在implode函數上使用update一次?在此先感謝
edit2.blade.php(.584編輯頁面,如圖所示它是一個數組)
<form class="form-horizontal" method="post" action="{{ url('/user/show/'.$object3->id) }}">
{{ method_field('PUT') }}
{{ csrf_field() }}
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr >
<th class="text-center">
#
</th>
<th class="text-center">
Sports:
</th>
<th class="text-center">
Books read:
</th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td>
1
</td>
<td>
<input type="text" name='computer_game[]' class="form-control"/>
</td>
<td>
<input type="text" name='reading_book[]' class="form-control"/>
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
<input type="submit" class="btn btn-primary" value="Save">
'var_dump($ request-> computer_game)'產生了什麼? – mulquin
你能告訴我們var_dump($ request-> computer_game)的返回值嗎? – Maraboc
@Maraboc它什麼也沒有 – blastme