簡體   English   中英

在整數上調用成員函數 save()

[英]Call to a member function save() on integer

我正在嘗試進行簡單的保存,但出現此錯誤。

在整數上調用成員函數 save()

這是我的控制器代碼:

foreach ($request['array'] as $key => $value) {

    if(DB::table('users')->where('id',$value)->where('auth',0)->exists() == true){
        $c = DB::table('users')->where('id', $value);
        $c->auth_teacher = '1';
        $c->update();
    }
}

編輯:

現在進行了更改,我得到了這個:

update() 必須是數組類型,沒有給出

因為您在此行上將 $c 設置為 1:

       $c = DB::table('users')->where('id', $value)->auth_teacher = 1;

試試這個方法

  foreach ($request['array'] as $key => $value) {

    if(DB::table('users')->where('id',$value)->where('auth',0)->exists() == true){
       DB::table('users')->where('id', $value)->update(['auth_teacher' => 1]);
    }

  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM