laravel 4 - Call to undefined method Illuminate\Database\Query\Builder::save()? -


i'm getting error after trying save model. error i'm getting:

call undefined method illuminate\database\query\builder::save()

this code:

public function getactivate ($code) {     $user = user::where('code','=',$code)->where('active','=',0);      if ($user->count())     {         $user->first();         //update user active state         $user->active = 1;         $user->code ='';          if($user->save())          {             return redirect::route('home')                             ->with('global', 'account activated ! can sign in ');         }     }      return redirect::route('home')                     ->with('global', 'we not activate account. try again later'); } 

my version of laravel stable one.

the problem not getting first instance of user, , calling save() on query itself.

here updated code:

public function getactivate ($code) {     $user = user::where('code','=',$code)->where('active','=',0)->first();      if ($user)     {         //update user active state         $user->active = 1;         $user->code ='';          if($user->save())          {             return redirect::route('home')                             ->with('global', 'account activated ! can sign in ');         }     }      return redirect::route('home')                     ->with('global', 'we not activate account. try again later'); } 

also, may simplify query build replacing where($column, '=', $query) to

$user = user::wherecode($code)->whereactive(0)->first(); 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -