我似乎无法更新我的用户和学校表,但现在能够更新爱好表。
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', 'HomeController@edit');
Route::put('/user/show/{id}','HomeController@update');
Route::get('/user/show/{id}/edit1', 'HomeController@edit1');
Route::put('/user/show/{id}','HomeController@update1');
Route::get('/user/show/{id}/edit2', 'HomeController@edit2');
Route::put('/user/show/{id}','HomeController@update2');
答案 0 :(得分:5)
问题在于您的路线:
Route::put('/user/show/{id}','HomeController@update');
Route::put('/user/show/{id}','HomeController@update1');
Route::put('/user/show/{id}','HomeController@update2');
三种方法的路线相同。
只是为了进行测试,你可以这样做:
Route::put('/user/show/{id}','HomeController@update');
Route::put('/user/showupdate1/{id}','HomeController@update1');
Route::put('/user/showupdate2/{id}','HomeController@update2');
在视图中更改这将完美地运作:)