简体   繁体   中英

Call to a member function save() on integer

I'm trying to do a simple save but I get this error.

Call to a member function save() on integer

Here is my code from controller:

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();
    }
}

EDIT:

Made changes now I get this:

update() must be of the type array, none given

因为您在此行上将 $c 设置为 1:

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

Try this approach

  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]);
    }

  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM