php - How to update a model with more conditions than an ID in Laravel? -


i'm new in laravel 5.0 , trying find user update him conditions status or expiration date. when use find method given user id ok update cause app\user instance possible update: $user->fill($newdata)->save();

but when need set conditions query, instance illuminate\database\eloquent\builder , not have fill method cause isn't app\user (isn't eloquent model):

$user = \reverse\interest::find($id)     ->where('status', '<>', 'deleted')     ->where('expires_at', '>=', db::raw('now()')) 

so, $user->fill($newdata)->save() impossible...

how find user id , more conditions , app\user instance update instead illuminate\database\eloquent\builder instance?

just call first() , use where('id', ...:

$user = \reverse\interest::where('id', $id)     ->where('status', '<>', 'deleted')     ->where('expires_at', '>=', db::raw('now()'))     ->first();  if($user !== null){     $user->fill($newdata)->save(); } 

Popular posts from this blog