错误:在数组laravel

时间:2017-10-20 03:04:51

标签: php arrays laravel laravel-5.3

我收到此错误"调用数组"上的成员函数update()我不知道为什么,是因为我正在更新数组?我检查了与此相似的其他资源,但与数组没有多大关系,所以我不知道该怎么做。提前谢谢

信息:我正在尝试更新HTML表,但一直收到此错误

控制器:

public function update1(Request $request, $id){
    $object2 = qualification::find($id);
    $object2 = array();
$object2['School'] = implode(' , ', $request->School);
$object2['SDate'] = implode(' , ', $request->SDate);
$object2['EDate'] = implode(' , ', $request->EDate);
$object2['qualification'] = implode(' , ', $request->qualification);
 $object2->update();
    return redirect('/home');
}

资格模型:

class qualification extends Eloquent
{
    protected $fillable = array('School', 'user_id', 'SDate', 'EDate', 'qualification');

    // DEFINE RELATIONSHIPS --------------------------------------------------
    public function personal_infos() {
        return $this->belongsTo('App\personal_info');
    }
}

1 个答案:

答案 0 :(得分:1)

您需要单独或一次性设置Qualification模型的属性,然后调用save()

public function update1(Request $request, $id){
    $object2 = qualification::find($id);
    $test = array();
    $test['School'] = implode(' , ', $request->School);
    $test['SDate'] = implode(' , ', $request->SDate);
    $test['EDate'] = implode(' , ', $request->EDate);
    $test['qualification'] = implode(' , ', $request->qualification);
    $object2->update($test);
    return redirect('/home');
}