我似乎无法更新我的用户和学校表了,但现在能够更新爱好表。模型不更新laravel
Keep getting error: implode(): Invalid arguments passed when updating data - >反向链接到这个问题之前
控制器:
//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');
}
// The error starts 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();
$reading_book = (array)$request->reading_book;
$test2['reading_book'] = implode(' , ',$reading_book);
$computer_game = (array)$request->computer_game;
$test2['computer_game'] = implode(' , ',$computer_game);
$object3->update($test2);
return redirect('/home');
}
业余爱好模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Eloquent;
class hobby extends Eloquent
{
protected $fillable = array('reading_book','computer_game','user_id');
public function users() {
return $this->belongsTo('App\user, 'user_id', 'id');
}
}
路线:(目前使用这些用于更新)
Route::get('/user/show/{id}/edit', '[email protected]');
Route::put('/user/show/{id}','[email protected]');
Route::get('/user/show/{id}/edit1', '[email protected]');
Route::put('/user/show/{id}','[email protected]');
Route::get('/user/show/{id}/edit2', '[email protected]');
Route::put('/user/show/{id}','[email protected]');
您能不能告诉我们您所使用的路线? – phaberest
有没有任何错误? – Maraboc
你在上一个问题中得到了答案吗? [保持错误:implode():更新数据时传递的参数无效](https://stackoverflow.com/questions/46845065/keep-getting-error-implode-invalid-arguments-passed-when-updating-data/46845303 ?noredirect = 1#comment80638799_46845303) – ljubadr